[Editor] Add Ctrl+Enter shortcut to executing executable scripts

This commit is contained in:
2021-03-25 11:20:43 +01:00
parent fc8dbda165
commit 30aff8f864
3 changed files with 9 additions and 1 deletions

View File

@@ -14,6 +14,7 @@ import org.fxmisc.richtext.model.StyleSpans
import java.time.Duration import java.time.Duration
import java.util.* import java.util.*
import java.util.concurrent.Executors import java.util.concurrent.Executors
import kotlin.math.max
class CodeEditor( class CodeEditor(
@@ -71,7 +72,7 @@ class CodeEditor(
private fun initAutoIndents() { private fun initAutoIndents() {
editor.addEventHandler(KeyEvent.KEY_PRESSED) { event -> editor.addEventHandler(KeyEvent.KEY_PRESSED) { event ->
if (event.code === KeyCode.ENTER) { if (event.code === KeyCode.ENTER) {
WHITESPACE.find(editor.getParagraph(editor.currentParagraph - 1).segments[0])?.apply { WHITESPACE.find(editor.getParagraph(max(editor.currentParagraph - 1, 0)).segments[0])?.apply {
editor.insertText(editor.caretPosition, value) editor.insertText(editor.caretPosition, value)
} }
} }

View File

@@ -1,6 +1,7 @@
package com.bartlomiejpluta.base.editor.code.view.editor package com.bartlomiejpluta.base.editor.code.view.editor
import com.bartlomiejpluta.base.editor.main.component.EditorFragment import com.bartlomiejpluta.base.editor.main.component.EditorFragment
import com.bartlomiejpluta.base.editor.main.component.EditorTab.Companion.EXECUTE_SHORTCUT
import com.bartlomiejpluta.base.editor.main.component.EditorTab.Companion.REDO_SHORTCUT import com.bartlomiejpluta.base.editor.main.component.EditorTab.Companion.REDO_SHORTCUT
import com.bartlomiejpluta.base.editor.main.component.EditorTab.Companion.SAVE_SHORTCUT import com.bartlomiejpluta.base.editor.main.component.EditorTab.Companion.SAVE_SHORTCUT
import com.bartlomiejpluta.base.editor.main.component.EditorTab.Companion.UNDO_SHORTCUT import com.bartlomiejpluta.base.editor.main.component.EditorTab.Companion.UNDO_SHORTCUT
@@ -17,6 +18,11 @@ class CodeEditorFragment : EditorFragment() {
override fun handleShortcut(event: KeyEvent) { override fun handleShortcut(event: KeyEvent) {
when { when {
EXECUTE_SHORTCUT.match(event) -> {
editorView.execute()
event.consume()
}
SAVE_SHORTCUT.match(event) -> { SAVE_SHORTCUT.match(event) -> {
editorView.save() editorView.save()
event.consume() event.consume()

View File

@@ -15,6 +15,7 @@ class EditorTab<T : EditorFragment>(val fragment: T, graphic: Node) : Tab() {
fun handleShortcut(event: KeyEvent) = fragment.handleShortcut(event) fun handleShortcut(event: KeyEvent) = fragment.handleShortcut(event)
companion object { companion object {
val EXECUTE_SHORTCUT = keyCombination("Ctrl+Enter")!!
val SAVE_SHORTCUT = keyCombination("Ctrl+S")!! val SAVE_SHORTCUT = keyCombination("Ctrl+S")!!
val UNDO_SHORTCUT = keyCombination("Ctrl+Z")!! val UNDO_SHORTCUT = keyCombination("Ctrl+Z")!!
val REDO_SHORTCUT = keyCombination("Ctrl+Y")!! val REDO_SHORTCUT = keyCombination("Ctrl+Y")!!