diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-09-19 23:16:23 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-09-19 23:16:23 -0700 |
commit | 593b95246c971bce26650141a7e3a0502c4abedb (patch) | |
tree | fbd4ed5a83633ca356d382b55da7973266ef18fb /apps | |
parent | e43ff485e6fcff8cbf004d8db00c489a60437094 (diff) | |
download | mu-593b95246c971bce26650141a7e3a0502c4abedb.tar.gz |
6814 - tile: backspace deletes char or word
Diffstat (limited to 'apps')
-rw-r--r-- | apps/tile/environment.mu | 28 | ||||
-rw-r--r-- | apps/tile/gap-buffer.mu | 6 | ||||
-rw-r--r-- | apps/tile/word.mu | 24 |
3 files changed, 58 insertions, 0 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index 275b87df..caa8c720 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -93,9 +93,36 @@ $process:body: { } break $process:body } + compare key, 0x7f # del (backspace on Macs) + { + break-if-!= + 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 of some word, delete grapheme before cursor within current word + var at-start?/eax: boolean <- cursor-at-start? cursor-word + compare at-start?, 0 # false + { + break-if-= + delete-before-cursor cursor-word + break $process:body + } + # otherwise delete current word and move 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 + delete-next prev-word + } + break $process:body + } compare key, 0x20 # space { break-if-!= + # insert new word var cursor-word-ah/edx: (addr handle word) <- get self, cursor-word append-word cursor-word-ah var cursor-word/eax: (addr word) <- lookup *cursor-word-ah @@ -103,6 +130,7 @@ $process:body: { copy-object next-word-ah, cursor-word-ah break $process:body } + # otherwise insert key within current word var g/edx: grapheme <- copy key var print?/eax: boolean <- real-grapheme? key { diff --git a/apps/tile/gap-buffer.mu b/apps/tile/gap-buffer.mu index 8a57fc5b..3d001cf6 100644 --- a/apps/tile/gap-buffer.mu +++ b/apps/tile/gap-buffer.mu @@ -169,6 +169,12 @@ fn gap-index _self: (addr gap-buffer) -> result/eax: int { result <- copy *top-addr } +fn delete-before-gap _self: (addr gap-buffer) { + var self/eax: (addr gap-buffer) <- copy _self + var left/eax: (addr grapheme-stack) <- get self, left + var dummy/eax: grapheme <- pop-grapheme-stack left +} + fn gap-buffer-equal? _self: (addr gap-buffer), s: (addr array byte) -> result/eax: boolean { $gap-buffer-equal?:body: { var self/esi: (addr gap-buffer) <- copy _self diff --git a/apps/tile/word.mu b/apps/tile/word.mu index cbc3c90d..9145f1d5 100644 --- a/apps/tile/word.mu +++ b/apps/tile/word.mu @@ -140,6 +140,30 @@ fn cursor-index _self: (addr word) -> result/eax: int { result <- gap-index data } +fn delete-before-cursor _self: (addr word) { + var self/esi: (addr word) <- copy _self + var data/eax: (addr gap-buffer) <- get self, data + delete-before-gap data +} + +fn delete-next _self: (addr word) { +$delete-next:body: { + var self/esi: (addr word) <- copy _self + var next-ah/edi: (addr handle word) <- get self, next + var next/eax: (addr word) <- lookup *next-ah + compare next, 0 + break-if-= $delete-next:body + var next-next-ah/ecx: (addr handle word) <- get next, next + var self-ah/esi: (addr handle word) <- get next, prev + copy-object next-next-ah, next-ah + var new-next/eax: (addr word) <- lookup *next-next-ah + compare new-next, 0 + break-if-= $delete-next:body + var dest/eax: (addr handle word) <- get new-next, prev + copy-object self-ah, dest +} +} + 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 |