Skip to content

Commit b112731

Browse files
Desc
1 parent 622caf8 commit b112731

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

src/components/Item.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@
291291
on:change={handleDescriptionChange}
292292
on:delete={handleExitDescription}
293293
on:exitdescription={handleExitDescription}
294+
on:selectup={handleExitDescription}
295+
on:selectdown={handleSelectDown}
294296
on:togglecomplete={handleToggleComplete}
295297
on:hashtagclick={handleHashtagClick}
296298
on:itemrefclick={handleItemRefClick}

src/components/List.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@
351351
on:change={handleDescriptionChange}
352352
on:delete={handleExitDescription}
353353
on:exitdescription={handleExitDescription}
354+
on:selectup={focusZoomedTitle}
355+
on:selectdown={handleTitleSelectDown}
354356
on:blur={handleDescriptionBlur}
355357
/>
356358
</div>

src/components/RichEditor.svelte

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,31 @@
252252
.run()
253253
}
254254
}
255+
256+
function handleKeydown(event) {
257+
if (isDescription) {
258+
// Basic stop propagation for everything.
259+
// KeyboardExtension will handle Enter, Shift-Enter, Arrows etc.
260+
// Since it's inside the container, it will see the event before this handler (bubbling phase).
261+
// Or rather, if we use a regular Svelte on:keydown, it's a bubbling listener on the div.
262+
event.stopPropagation()
263+
}
264+
}
265+
266+
function handleMousedown(event) {
267+
if (isDescription) {
268+
event.stopPropagation()
269+
}
270+
}
255271
</script>
256272
257273
<div class="rich-editor-wrapper" class:description={isDescription} class:zoomed-root={isZoomedRoot}>
258274
<div
259275
bind:this={editorElement}
260276
class="editor-container"
277+
on:keydown={handleKeydown}
278+
on:mousedown={handleMousedown}
279+
role="presentation"
261280
></div>
262281
263282
<div bind:this={bubbleMenuElement} class="bubble-menu">

src/extensions/KeyboardExtension.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,38 @@ export const KeyboardExtension = Extension.create({
102102
return false
103103
},
104104

105-
'ArrowUp': () => {
105+
'ArrowUp': ({ editor }) => {
106+
if (this.options.isDescription) {
107+
const { state } = editor
108+
const { selection } = state
109+
if (selection.from === 1) {
110+
if (this.options.onArrowUp) {
111+
this.options.onArrowUp()
112+
return true
113+
}
114+
}
115+
return false
116+
}
106117
if (this.options.onArrowUp) {
107118
this.options.onArrowUp()
108119
return true
109120
}
110121
return false
111122
},
112123

113-
'ArrowDown': () => {
124+
'ArrowDown': ({ editor }) => {
125+
if (this.options.isDescription) {
126+
const { state } = editor
127+
const { selection, doc } = state
128+
// doc.content.size - 1 is the end of the last node's content
129+
if (selection.to >= doc.content.size - 1) {
130+
if (this.options.onArrowDown) {
131+
this.options.onArrowDown()
132+
return true
133+
}
134+
}
135+
return false
136+
}
114137
if (this.options.onArrowDown) {
115138
this.options.onArrowDown()
116139
return true

0 commit comments

Comments
 (0)