Skip to content

Commit ba23ace

Browse files
authored
#7973 undoing shouldnt work when input is focused (#7976)
* disable undo invoked by electron file menu if input is focused * cleanup: remove unused params * execute actual undo when input is focused * tsc
1 parent abd1665 commit ba23ace

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

src/components/FileMachineProvider.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,7 @@ export const FileMachineProvider = ({
433433
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: blanket-ignored fix me!
434434
}, [location])
435435

436-
const cb = modelingMenuCallbackMostActions(
437-
settings,
438-
navigate,
439-
filePath,
440-
project,
441-
token
442-
)
436+
const cb = modelingMenuCallbackMostActions(settings, navigate, filePath)
443437
useMenuListener(cb)
444438

445439
const kclCommandMemo = useMemo(() => {

src/components/ModelingPageProvider.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,7 @@ export const ModelingPageProvider = ({
107107
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: blanket-ignored fix me!
108108
}, [location])
109109

110-
const cb = modelingMenuCallbackMostActions(
111-
settings,
112-
navigate,
113-
filePath,
114-
project,
115-
token
116-
)
110+
const cb = modelingMenuCallbackMostActions(settings, navigate, filePath)
117111
useMenuListener(cb)
118112

119113
const kclCommandMemo = useMemo(() => {

src/lib/utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ export async function refreshPage(method = 'UI button') {
3838
window?.location.reload()
3939
}
4040

41+
export function activeFocusIsInput() {
42+
return document.activeElement && isInputElement(document.activeElement)
43+
}
44+
45+
function isInputElement(
46+
element: EventTarget
47+
): element is HTMLInputElement | HTMLTextAreaElement {
48+
return (
49+
element instanceof HTMLInputElement ||
50+
element instanceof HTMLTextAreaElement
51+
)
52+
}
53+
4154
/**
4255
* Get all labels for a keyword call expression.
4356
*/

src/menu/register.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { AxisNames } from '@src/lib/constants'
22
import { PATHS } from '@src/lib/paths'
3-
import type { Project } from '@src/lib/project'
43
import type { SettingsType } from '@src/lib/settings/initialSettings'
54
import { engineCommandManager, sceneInfra } from '@src/lib/singletons'
65
import { reportRejection } from '@src/lib/trap'
7-
import { uuidv4 } from '@src/lib/utils'
6+
import { activeFocusIsInput, uuidv4 } from '@src/lib/utils'
87
import {
98
authActor,
109
commandBarActor,
@@ -17,9 +16,7 @@ import type { NavigateFunction } from 'react-router-dom'
1716
export function modelingMenuCallbackMostActions(
1817
settings: SettingsType,
1918
navigate: NavigateFunction,
20-
filePath: string,
21-
project: Project | undefined,
22-
token: string | undefined
19+
filePath: string
2320
) {
2421
// Menu listeners
2522
const cb = (data: WebContentSendPayload) => {
@@ -124,9 +121,19 @@ export function modelingMenuCallbackMostActions(
124121
data: { name: 'format-code', groupId: 'code' },
125122
})
126123
} else if (data.menuLabel === 'Edit.Undo') {
127-
editorManager.undo()
124+
if (activeFocusIsInput()) {
125+
document.execCommand('undo')
126+
// Cleaner, but can't import 'electron' to this file:
127+
// webContents.getFocusedWebContents()?.undo()
128+
} else {
129+
editorManager.undo()
130+
}
128131
} else if (data.menuLabel === 'Edit.Redo') {
129-
editorManager.redo()
132+
if (activeFocusIsInput()) {
133+
document.execCommand('redo')
134+
} else {
135+
editorManager.redo()
136+
}
130137
} else if (data.menuLabel === 'View.Orthographic view') {
131138
settingsActor.send({
132139
type: 'set.modeling.cameraProjection',

0 commit comments

Comments
 (0)