Skip to content

Commit

Permalink
fix: code span
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentdchan committed Nov 25, 2023
1 parent 1a15593 commit 31f1fc5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
11 changes: 10 additions & 1 deletion packages/blocky-core/src/block/textBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,15 @@ export class TextBlock extends ContentBlock {
if (key === "href") {
continue;
}
if (attributes[key] && !span.classList.contains(key)) {
const spanDef = this.editor.registry.span.styles.get(key);
if (!spanDef) {
return false;
}
if (
attributes[key] &&
isString(spanDef.className) &&
!span.classList.contains(spanDef.className)
) {
return false;
}
}
Expand Down Expand Up @@ -790,6 +798,7 @@ export class TextBlock extends ContentBlock {
} else {
// is old
if (!this.#isSpanNodeMatch(op, domPtr)) {
console.log("not match", op, domPtr);
const oldDom = domPtr;
const newNode = this.#createDomByOp(op, this.editor);

Expand Down
34 changes: 20 additions & 14 deletions packages/blocky-core/src/plugins/codeTextPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CursorState, Changeset } from "@pkg/data";
import Delta from "quill-delta-es";
import { isHotkey } from "is-hotkey";
import { isUndefined } from "lodash-es";
import { takeUntil } from "rxjs";
import { takeUntil, filter } from "rxjs";

class CodeTextDetector {
#cursor: CursorState;
Expand Down Expand Up @@ -49,16 +49,21 @@ function makeCodeTextPlugin(): IPlugin {
],
onInitialized(context: PluginContext) {
const { editor, dispose$ } = context;
editor.keyDown$
.pipe(
takeUntil(dispose$),
filter((e: KeyboardEvent) => isHotkey("mod+m", e))
)
.subscribe((e: KeyboardEvent) => {
e.preventDefault();
editor.controller.formatTextOnSelectedText({
code: true,
});
});

editor.keyDown$
.pipe(takeUntil(dispose$))
.subscribe((e: KeyboardEvent) => {
if (isHotkey("mod+m", e)) {
e.preventDefault();
editor.controller.formatTextOnSelectedText({
code: true,
});
return;
}
if (editor.composing) {
return;
}
Expand Down Expand Up @@ -107,12 +112,13 @@ function makeCodeTextPlugin(): IPlugin {
}
}
}
} else {
if (codeTextDetector) {
if (!codeTextDetector.emitNonDot(editor.state.cursorState)) {
codeTextDetector = undefined;
}
}
return;
}
if (
codeTextDetector &&
!codeTextDetector.emitNonDot(editor.state.cursorState)
) {
codeTextDetector = undefined;
}
});
},
Expand Down

1 comment on commit 31f1fc5

@vercel
Copy link

@vercel vercel bot commented on 31f1fc5 Nov 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.