From 19c3a42d60018731585eaa5e7dcf690350bf7418 Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Sun, 20 Apr 2025 22:48:40 +1000 Subject: [PATCH] Script Editor: Add shortcut key Shift+Cmd+K/Shift+Ctrl+K to delete the current line (#3156) This shortcut is quite well known from VS Code. It is basically the same as Cmd+X / Ctrl X, but without putting the deleted stuff into the clipboard. Signed-off-by: Jimmy Tanagra --- .../config/controls/script-editor.vue | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/components/config/controls/script-editor.vue b/bundles/org.openhab.ui/web/src/components/config/controls/script-editor.vue index 754d3e7b5..d610cc027 100644 --- a/bundles/org.openhab.ui/web/src/components/config/controls/script-editor.vue +++ b/bundles/org.openhab.ui/web/src/components/config/controls/script-editor.vue @@ -320,14 +320,29 @@ export default { } } extraKeys['Shift-Tab'] = 'indentLess' - extraKeys['Cmd-/'] = 'toggleComment' - extraKeys['Ctrl-/'] = 'toggleComment' + extraKeys['Cmd-/'] = extraKeys['Ctrl-/'] = 'toggleComment' + extraKeys['Shift-Cmd-K'] = extraKeys['Shift-Ctrl-K'] = this.deleteCurrentLine cm.setOption('extraKeys', extraKeys) cm.addOverlay(indentGuidesOverlay) cm.refresh() }, onCmCodeChange (newCode) { this.$emit('input', newCode) + }, + deleteCurrentLine (cm) { + if (cm.somethingSelected()) { + cm.replaceSelection('') + } else { + const cursor = cm.getCursor() + if (cursor.line === cm.lastLine() && cursor.line !== cm.firstLine()) { + const prevLine = cursor.line - 1 + cm.replaceRange('', { line: prevLine, ch: cm.getLine(prevLine).length }, { line: cursor.line, ch: cm.getLine(cursor.line).length }) + cm.setCursor({ line: prevLine, ch: 0 }) + } else { + cm.replaceRange('', { line: cursor.line, ch: 0 }, { line: cursor.line + 1, ch: 0 }) + cm.setCursor({ line: cursor.line, ch: 0 }) + } + } } }, computed: {