Skip to content

Commit 79df8b9

Browse files
committed
Fix cursor navigation and backspace functionality CodeTool
1 parent e34a438 commit 79df8b9

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

dev/index.html

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Code Plugin Test | EditorJS</title>
7+
</head>
8+
<body>
9+
<div id="editorjs"></div>
10+
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest/dist/editor.js"></script>
11+
<script src="https://cdn.jsdelivr.net/npm/@editorjs/header@latest"></script>
12+
<script src="../dist/code.umd.js"></script>
13+
<script>
14+
const editor = new EditorJS({
15+
holder: 'editorjs',
16+
data: {
17+
time: 1700475383740,
18+
blocks: [
19+
{
20+
id: 'aRMoZePSTD',
21+
type: 'header',
22+
data: { text: 'Welcome to Editor.js', level: 2 },
23+
},
24+
{
25+
id: 'fcG8CCR5F8',
26+
type: 'code',
27+
data: { code: 'print("Namaste World")' },
28+
},
29+
],
30+
},
31+
tools: {
32+
code: CodeTool,
33+
header: Header,
34+
},
35+
});
36+
</script>
37+
</body>
38+
</html>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/code",
3-
"version": "2.9.2",
3+
"version": "2.9.3",
44
"keywords": [
55
"codex editor",
66
"code",

src/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,19 @@ export default class CodeTool implements BlockTool {
317317
case 'Tab':
318318
this.tabHandler(event);
319319
break;
320+
case 'Backspace':
321+
if (textarea.value.length > 0) {
322+
event.stopPropagation();
323+
} else {
324+
event.preventDefault();
325+
}
326+
break;
327+
case 'ArrowUp':
328+
case 'ArrowDown':
329+
case 'ArrowLeft':
330+
case 'ArrowRight':
331+
event.stopPropagation();
332+
break;
320333
}
321334
});
322335

0 commit comments

Comments
 (0)