diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-10-25 14:34:40 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-10-25 14:34:40 -0700 |
commit | f37e7f33e8cf57f82181ce137ab74ec5cd28e1d9 (patch) | |
tree | dc7eeea4dffc4c77fa2741a3a20d3c338922aabf /apps/tile | |
parent | 4dad0efa8dfe7f7ce339f7d2d7b1aa817810665d (diff) | |
download | mu-f37e7f33e8cf57f82181ce137ab74ec5cd28e1d9.tar.gz |
7098 - tile: string values
Strings can contain spaces.
Diffstat (limited to 'apps/tile')
-rw-r--r-- | apps/tile/data.mu | 4 | ||||
-rw-r--r-- | apps/tile/environment.mu | 10 | ||||
-rw-r--r-- | apps/tile/gap-buffer.mu | 18 | ||||
-rw-r--r-- | apps/tile/main.mu | 14 | ||||
-rw-r--r-- | apps/tile/word.mu | 7 |
5 files changed, 38 insertions, 15 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu index 03f66bd2..3cd2337d 100644 --- a/apps/tile/data.mu +++ b/apps/tile/data.mu @@ -28,11 +28,7 @@ type line { } type word { - # at most one of these will be non-null scalar-data: (handle gap-buffer) - text-data: (handle array byte) - box-data: (handle line) # recurse - # next: (handle word) prev: (handle word) } diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index f8daaddd..2cc552c0 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -423,6 +423,16 @@ $process-sandbox:body: { decrement-final-element cursor-call-path break $process-sandbox:body } + # if start of word is quote and grapheme before cursor is not, just insert it as usual + { + var first-grapheme/eax: grapheme <- first-grapheme cursor-word + compare first-grapheme, 0x22 # double quote + break-if-!= + var final-grapheme/eax: grapheme <- grapheme-before-cursor cursor-word + compare final-grapheme, 0x22 # double quote + break-if-= + break $process-sandbox:space + } # otherwise insert word after and move cursor to it for the next key # (but we'll continue to track the current cursor-word for the rest of this function) append-word cursor-word-ah diff --git a/apps/tile/gap-buffer.mu b/apps/tile/gap-buffer.mu index 627a6877..cfd3d02d 100644 --- a/apps/tile/gap-buffer.mu +++ b/apps/tile/gap-buffer.mu @@ -210,6 +210,24 @@ $first-grapheme-in-gap-buffer:body: { } } +fn grapheme-before-cursor-in-gap-buffer _self: (addr gap-buffer) -> result/eax: grapheme { +$grapheme-before-cursor-in-gap-buffer:body: { + var self/esi: (addr gap-buffer) <- copy _self + # try to read from left + var left/ecx: (addr grapheme-stack) <- get self, left + var top-addr/edx: (addr int) <- get left, top + compare *top-addr, 0 + { + break-if-<= + result <- pop-grapheme-stack left + push-grapheme-stack left, result + break $grapheme-before-cursor-in-gap-buffer:body + } + # give up + result <- copy -1 +} +} + 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 diff --git a/apps/tile/main.mu b/apps/tile/main.mu index 4cf325a1..d4f53535 100644 --- a/apps/tile/main.mu +++ b/apps/tile/main.mu @@ -75,21 +75,13 @@ fn test { var env-storage: environment var env/esi: (addr environment) <- address env-storage initialize-environment-with-fake-screen env, 5, 0xa - var g/eax: grapheme <- copy 0x31 # '1' + var g/eax: grapheme <- copy 0x22 # '"' process env, g - g <- copy 0x20 # space - process env, g - g <- copy 0x32 # '2' - process env, g - g <- copy 0x33 # '3' - process env, g - g <- copy 0x445b1b # left-arrow - process env, g - g <- copy 0x445b1b # left-arrow + g <- copy 0x31 # '1' process env, g g <- copy 0x20 # space process env, g - g <- copy 0x445b1b # left-arrow + g <- copy 0x33 # '3' process env, g } diff --git a/apps/tile/word.mu b/apps/tile/word.mu index 994f3819..9e8fb45e 100644 --- a/apps/tile/word.mu +++ b/apps/tile/word.mu @@ -150,6 +150,13 @@ fn first-grapheme _self: (addr word) -> result/eax: grapheme { result <- first-grapheme-in-gap-buffer data } +fn grapheme-before-cursor _self: (addr word) -> result/eax: grapheme { + var self/esi: (addr word) <- copy _self + var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data + var data/eax: (addr gap-buffer) <- lookup *data-ah + result <- grapheme-before-cursor-in-gap-buffer data +} + fn add-grapheme-to-word _self: (addr word), c: grapheme { var self/esi: (addr word) <- copy _self var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data |