diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-09-19 22:33:44 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-09-19 22:33:44 -0700 |
commit | f32e575e387859af74f7023f9f02b32dee839962 (patch) | |
tree | 6c8c7115a8d0397f2154338c786308fa1c0f96a0 | |
parent | 4449f4878138e2d7baa2b227098e2d03d0342f39 (diff) | |
download | mu-f32e575e387859af74f7023f9f02b32dee839962.tar.gz |
6811 - tile: left-cursor movement
Displayed cursor position is not yet correct, but insertions happen at the right cursor position.
-rw-r--r-- | apps/tile/environment.mu | 25 | ||||
-rw-r--r-- | apps/tile/gap-buffer.mu | 12 | ||||
-rw-r--r-- | apps/tile/word.mu | 36 |
3 files changed, 68 insertions, 5 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index 73162caf..c57c64e7 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -46,11 +46,26 @@ $process:body: { compare key, 0x445b1b # left-arrow { break-if-!= - # TODO: - # gap-left cursor-word - # or - # cursor-word = cursor-word->prev - # gap-to-end cursor-word + var cursor-word-ah/edi: (addr handle word) <- get self, cursor-word + var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah + var cursor-word/ecx: (addr word) <- copy _cursor-word + # if not at start, gap-left + var at-start?/eax: boolean <- cursor-at-start? cursor-word + compare at-start?, 0 # false + { + break-if-= + cursor-left cursor-word + break $process:body + } + # otherwise, move gap to end of prev word + var prev-word-ah/esi: (addr handle word) <- get cursor-word, prev + var prev-word/eax: (addr word) <- lookup *prev-word-ah + { + compare prev-word, 0 + break-if-= + copy-object prev-word-ah, cursor-word-ah + cursor-to-end prev-word + } break $process:body } compare key, 0x435b1b # right-arrow diff --git a/apps/tile/gap-buffer.mu b/apps/tile/gap-buffer.mu index 75f88122..96e39aed 100644 --- a/apps/tile/gap-buffer.mu +++ b/apps/tile/gap-buffer.mu @@ -114,6 +114,18 @@ fn gap-to-end self: (addr gap-buffer) { } } +fn gap-at-start? _self: (addr gap-buffer) -> result/eax: boolean { + var self/esi: (addr gap-buffer) <- copy _self + var left/eax: (addr grapheme-stack) <- get self, left + result <- grapheme-stack-empty? left +} + +fn gap-at-end? _self: (addr gap-buffer) -> result/eax: boolean { + var self/esi: (addr gap-buffer) <- copy _self + var right/eax: (addr grapheme-stack) <- get self, right + result <- grapheme-stack-empty? right +} + fn gap-right _self: (addr gap-buffer) -> result/eax: grapheme { $gap-right:body: { var self/esi: (addr gap-buffer) <- copy _self diff --git a/apps/tile/word.mu b/apps/tile/word.mu index 9e683985..4c7b13dd 100644 --- a/apps/tile/word.mu +++ b/apps/tile/word.mu @@ -98,6 +98,42 @@ fn add-grapheme-to-word _self: (addr word), c: grapheme { add-grapheme-at-gap data, c } +fn cursor-at-start? _self: (addr word) -> result/eax: boolean { + var self/esi: (addr word) <- copy _self + var data/eax: (addr gap-buffer) <- get self, data + result <- gap-at-start? data +} + +fn cursor-at-end? _self: (addr word) -> result/eax: boolean { + var self/esi: (addr word) <- copy _self + var data/eax: (addr gap-buffer) <- get self, data + result <- gap-at-end? data +} + +fn cursor-left _self: (addr word) { + var self/esi: (addr word) <- copy _self + var data/eax: (addr gap-buffer) <- get self, data + var dummy/eax: grapheme <- gap-left data +} + +fn cursor-right _self: (addr word) { + var self/esi: (addr word) <- copy _self + var data/eax: (addr gap-buffer) <- get self, data + var dummy/eax: grapheme <- gap-right data +} + +fn cursor-to-start _self: (addr word) { + var self/esi: (addr word) <- copy _self + var data/eax: (addr gap-buffer) <- get self, data + gap-to-start data +} + +fn cursor-to-end _self: (addr word) { + var self/esi: (addr word) <- copy _self + var data/eax: (addr gap-buffer) <- get self, data + gap-to-end data +} + fn print-word screen: (addr screen), _self: (addr word) { var self/esi: (addr word) <- copy _self var data/eax: (addr gap-buffer) <- get self, data |