Skip to content

Commit c8e255b

Browse files
committed
delegate editor events fix
2 parents 5c01097 + a077ba3 commit c8e255b

5 files changed

Lines changed: 81 additions & 12 deletions

File tree

src/core/custom/code-block/suggestion/code-block-suggestion-command.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,33 @@ import type { SuggestedChangeConfig } from '../../../../editor/utils/loadCodeSug
2020

2121
export function defineCodeBlockSuggestionCommand() {
2222
return defineCommands({
23-
insertCodeBlockSuggestion: (attrs: {
23+
insertCodeBlockSuggestion: (options: {
2424
suggestChange: SuggestedChangeConfig
2525
}) => {
26-
const lang = detectLanguageFromFilename(attrs.suggestChange.filePath!)
27-
return insertNode({
28-
type: 'codeBlock',
29-
attrs: {
30-
code: attrs.suggestChange.sourceContentFromDiffLines || '',
31-
lang: lang || '',
32-
isSuggestion: true,
33-
suggestedChangeConfig: attrs.suggestChange,
34-
},
35-
})
26+
const lang = detectLanguageFromFilename(options.suggestChange.filePath!)
27+
return (state, dispatch, view) => {
28+
const node = state.schema.nodes.codeBlock.create(
29+
{
30+
code: options.suggestChange.sourceContentFromDiffLines || '',
31+
lang: lang || '',
32+
isSuggestion: true,
33+
suggestChangeConfig: options.suggestChange,
34+
},
35+
state.schema.text(
36+
options.suggestChange.sourceContentFromDiffLines || '',
37+
),
38+
)
39+
40+
return insertNode({
41+
node,
42+
attrs: {
43+
code: options.suggestChange.sourceContentFromDiffLines || '',
44+
lang: lang || '',
45+
isSuggestion: true,
46+
suggestedChangeConfig: options.suggestChange,
47+
},
48+
})(state, dispatch, view)
49+
}
3650
},
3751
})
3852
}

src/core/editor/toolbar/toolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export function Toolbar() {
388388
</TooltipTrigger>
389389
<TooltipContent>Issues & Feedback</TooltipContent>
390390
</Tooltip>
391-
<Popover placement={'bottom-end'}>
391+
<Popover placement={'bottom-end'} modal={true}>
392392
<PopoverTrigger class={styles.ToolbarAction}>
393393
<LucideCog size={16} />
394394
</PopoverTrigger>

src/editor/editor.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
-webkit-font-variant-ligatures: none;
1212
font-variant-ligatures: none;
1313
font-feature-settings: 'liga' 0;
14+
caret-color: initial !important;
1415
}
1516

1617
.ProseMirror pre {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2025 Riccardo Perra
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { delegateEvents } from 'solid-js/web'
18+
19+
export function delegateEditorEvents(root: HTMLElement) {
20+
const delegatedEvents = [
21+
'beforeinput',
22+
'click',
23+
// 'dblclick',
24+
// 'contextmenu',
25+
'focusin',
26+
'focusout',
27+
'input',
28+
'keydown',
29+
'keyup',
30+
// 'mousedown',
31+
// 'mousemove',
32+
// 'mouseout',
33+
// 'mouseover',
34+
// 'mouseup',
35+
// 'pointerdown',
36+
// 'pointermove',
37+
// 'pointerout',
38+
// 'pointerover',
39+
// 'pointerup',
40+
// 'touchend',
41+
// 'touchmove',
42+
// 'touchstart',
43+
]
44+
delegateEvents(delegatedEvents, root as unknown as Document)
45+
delegatedEvents.forEach((event) => {
46+
root.addEventListener(event, (event) => {
47+
event.stopPropagation()
48+
event.stopImmediatePropagation()
49+
})
50+
})
51+
}

src/render.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { ConfettiExplosion } from 'solid-confetti-explosion'
2222
import { Editor, EditorRootContext } from './editor/editor'
2323
import { OcticonCaution } from './core/custom/githubAlert/icons'
2424
import { ConfigStore } from './config.store'
25+
import { delegateEditorEvents } from './editor/utils/eventDelegation'
2526
import type { EditorType } from './editor/editor'
2627
import type { Accessor } from 'solid-js'
2728
import type { GitHubUploaderHandler } from './core/custom/image/github-file-uploader'
@@ -138,6 +139,8 @@ export function EditorErrorBoundary(props: EditorErrorBoundaryProps) {
138139
}
139140

140141
export function mountEditor(root: HTMLElement, props: RenderEditorProps) {
142+
delegateEditorEvents(root)
143+
141144
return render(() => {
142145
return (
143146
<StateProvider>

0 commit comments

Comments
 (0)