summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2022-08-19 07:47:25 +0200
committerPhilipp Gesang <phg@phi-gamma.net>2022-08-19 07:47:28 +0200
commit305a7c2a22b02dde982f1b9fa60db6d277a3bc91 (patch)
treeeb795505e6040b9c6f7ded08dc639ad3f0b3d453 /src
parenta1f457d71622649a1b1a84c00d200c8f1e315ab4 (diff)
downloadvtcol-305a7c2a22b02dde982f1b9fa60db6d277a3bc91.tar.gz
edit: implement basic insert mode switch
Where <i> or <CR> enter “insert mode” (i. e. activate the Edit widget) and <Esc> leaves it again.
Diffstat (limited to 'src')
-rw-r--r--src/edit.rs70
1 files changed, 47 insertions, 23 deletions
diff --git a/src/edit.rs b/src/edit.rs
index de0fa80..016ed9a 100644
--- a/src/edit.rs
+++ b/src/edit.rs
@@ -17,6 +17,7 @@ slint::slint! {
callback format-rgb-component(int) -> string;
callback color-of-rgb-component(string, int) -> color;
callback component-of-rgb(string, color) -> int;
+ property<bool> insert-mode: false;
}
Colors := Rectangle {
@@ -98,8 +99,10 @@ slint::slint! {
Edit := Rectangle {
width : 100%;
- border-width : 2px;
- background: @linear-gradient(90deg, #002b36 0%, #073642 100%);
+ background : @linear-gradient(90deg, #002b36 0%, #073642 100%);
+ border-color : Aux.insert-mode ? #cb4b16 : #839496;
+ border-width : 3px;
+
property<color> rgb : Colors.white;
callback update (color);
@@ -136,33 +139,48 @@ slint::slint! {
key-inputs := FocusScope {
key-pressed(event) => {
debug("input: got", event.text, "shift?", event.modifiers.shift);
- if (event.text == "q") {
- user-quit();
- }
- if (event.text == "h") {
- debug("select prev");
- master.select-prev();
- }
- else if (event.text == "l") {
- debug("select next");
- master.select-next();
+ /* Escape always gets you back to normal mode. */
+ if (event.text == Keys.Escape) {
+ debug("enter normal");
+ master.enter-normal-mode();
}
- else if (event.text == " ") {
- if (event.modifiers.shift) {
+ else if (Aux.insert-mode) {
+ /* In insert mode, most selection bindings are frozen. */
+ } /* Insert mode. */
+ else {
+ /* Normal mode bindings. */
+ if (event.text == "q") {
+ user-quit();
+ }
+ if (event.text == "h") {
debug("select prev");
master.select-prev();
- } else {
+ }
+ else if (event.text == "l") {
debug("select next");
master.select-next();
}
- }
- else if (event.text == "j" || event.text == "k") {
- debug("select other row");
- master.select-other-row();
- }
- if (event.modifiers.control) {
- //debug("control was pressed during this event");
- }
+ else if (event.text == " ") {
+ if (event.modifiers.shift) {
+ debug("select prev");
+ master.select-prev();
+ } else {
+ debug("select next");
+ master.select-next();
+ }
+ }
+ else if (event.text == "j" || event.text == "k") {
+ debug("select other row");
+ master.select-other-row();
+ }
+ else if (event.text == Keys.Return || event.text == "i") {
+ debug("enter insert");
+ master.enter-insert-mode();
+ }
+ if (event.modifiers.control) {
+ //debug("control was pressed during this event");
+ }
+ } /* Normal mode. */
edit.update(
Aux.selected < 8
? primary-colors.colors [Aux.selected]
@@ -192,6 +210,9 @@ slint::slint! {
callback select-next();
callback select-other-row();
+ callback enter-insert-mode();
+ callback enter-normal-mode();
+
select-prev () => {
Aux.select (Aux.selected == 0 ? 15 : Aux.selected - 1);
debug ("selected previous, now", Aux.selected);
@@ -207,6 +228,9 @@ slint::slint! {
debug ("selected row above/below, now", Aux.selected);
}
+ enter-normal-mode () => { Aux.insert-mode = false; }
+ enter-insert-mode () => { Aux.insert-mode = true; }
+
status := HorizontalBox {
width : 100%;