ProseMirror / prosemirror

The ProseMirror WYSIWYM editor
http://prosemirror.net/
MIT License
7.53k stars 334 forks source link

toggleMark will also toggle the whitespaces before except Firefox #1442

Closed Stardusten closed 5 months ago

Stardusten commented 5 months ago

In browser (Firefox), everything is fine:

pmbug2

But in Tauri, something strange happened, the whitespaces before will also be toggled to code:

pmbug1

Stardusten commented 5 months ago

I just tried Electron, and has the same problem.

marijnh commented 5 months ago

What, exactly, are you doing in that video? Pressing a keyboard shortcut to toggle code mark after pressing the space? Does this reproduce in Chrome?

Stardusten commented 5 months ago

I first type aaa<SPACE>, and then press Mod-<BACKTICK> (I bind Mod-<BACKTICK> to toggleMark(pmSchema.marks.code)).

I can reproduce this issue in Electron 28.1 with following code:

<script setup lang="ts">
import "prosemirror-example-setup/style/style.css"
import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {Schema} from "prosemirror-model"
import {schema} from "prosemirror-schema-basic"
import {addListNodes} from "prosemirror-schema-list"
import {exampleSetup} from "prosemirror-example-setup"
import {onMounted} from "vue";

const mySchema = new Schema({
  nodes: addListNodes(schema.spec.nodes, "paragraph block*", "block"),
  marks: schema.spec.marks
})

onMounted(() => {
  new EditorView(document.querySelector("#editor"), {
    state: EditorState.create({
      schema: mySchema,
      plugins: exampleSetup({schema: mySchema})
    })
  })
})
</script>

<template>
  <div id="editor"></div>
</template>
Stardusten commented 5 months ago

Does this reproduce in Chrome?

No, I tried the editor on ProseMirror's official website in Chrome, and everything seems fine. I will do some test to clarify this next.

Stardusten commented 5 months ago

I can reproduce this issue in Chrome Version 120.0.6099.71. I create a minimal reproduction repository for this: https://github.com/Stardusten/pm-test

Here are the core codes:

<script setup lang="ts">
import {EditorState} from "prosemirror-state";
import {EditorView} from "prosemirror-view";
import {Schema} from "prosemirror-model";
import {schema} from "prosemirror-schema-basic";
import {addListNodes} from "prosemirror-schema-list";
import {exampleSetup} from "prosemirror-example-setup";
import {onMounted} from "vue";

const mySchema = new Schema({
  nodes: addListNodes(schema.spec.nodes, "paragraph block*", "block"),
  marks: schema.spec.marks
})

onMounted(() => {
  new EditorView(document.querySelector("#editor"), {
    state: EditorState.create({
      schema: mySchema,
      plugins: exampleSetup({schema: mySchema})
    })
  })
})
</script>

<template>
  <div id="editor"></div>
</template>
marijnh commented 5 months ago

That repository (running npm run dev) gives me a weird mess of a page that isn't loading the ProseMirror style sheet. If I fix that, the problem goes away. So I think that's going to be your solution.

Stardusten commented 5 months ago

It works! Thanks a lot.