Skip to content

Commit

Permalink
fix: fix disabled rules
Browse files Browse the repository at this point in the history
  • Loading branch information
libra-co committed Oct 11, 2023
1 parent b4990c0 commit 776ea05
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/extension/plugins/code-block/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const isMenuDisabled = (editor, readonly) => {
const isSelectedVoid = selectedElements.some(node => editor.isVoid(node));
if (isSelectedVoid) return true;
// Disable the menu when selection is not in the paragraph or code block
const isEnable = selectedElements.find(node => ![CODE_BLOCK, PARAGRAPH].includes(node.type));
const isEnable = selectedElements.every(node => [CODE_BLOCK, PARAGRAPH].includes(node.type));
return !isEnable;
};

Expand Down
7 changes: 4 additions & 3 deletions src/extension/plugins/code-block/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const withCodeBlock = (editor) => {
};

newEditor.insertFragment = (data) => {
console.log('data', data)
// only selected code block content
if (data.length === 1 && data[0].type === CODE_BLOCK && !getSelectedNodeByType(editor, CODE_BLOCK)) {
data.forEach((node, index) => {
Expand All @@ -41,7 +42,7 @@ const withCodeBlock = (editor) => {
data.splice(index, 1, ...codeLineArr);
}
});
const newData = data.map(node => {
const insertCodeLines = data.map(node => {
const text = Node.string(node);
const codeLine = generateElementInCustom(CODE_LINE, text);
return codeLine;
Expand All @@ -50,7 +51,7 @@ const withCodeBlock = (editor) => {
// current focus code-line string not empty
const string = Editor.string(newEditor, newEditor.selection.focus.path);
if (string.length !== 0 && Range.isCollapsed(newEditor.selection)) {
const [node, ...restNode] = newData;
const [node, ...restNode] = insertCodeLines;
const text = Node.string(node);
insertText(text);
if (restNode.length !== 0) {
Expand All @@ -59,7 +60,7 @@ const withCodeBlock = (editor) => {
}
return;
}
return insertFragment(newData);
return insertFragment(insertCodeLines);
} else {
// Paste into not a code block
return insertFragment(data);
Expand Down

0 comments on commit 776ea05

Please sign in to comment.