about summary refs log tree commit diff stats
path: root/edit.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-09 20:01:42 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-09 20:01:42 -0700
commite709c65e67f873541b958ba43e425b08f3e073e3 (patch)
tree37d7203b4f2874e41e178938f1f00917dae949c8 /edit.mu
parent6fef33fd0872ffcb5141a926d1dae5b0eded3071 (diff)
downloadmu-e709c65e67f873541b958ba43e425b08f3e073e3.tar.gz
1964 - don't mess up paste
It took me a long time to fix termbox because the escape codes it was
seeing seemed all wrong. Had to stop calling tb_shutdown/printf and put
in the extra 3 lines to log to a file. Then everything cleared up.
Weird.
Diffstat (limited to 'edit.mu')
-rw-r--r--edit.mu61
1 files changed, 60 insertions, 1 deletions
diff --git a/edit.mu b/edit.mu
index 369d0089..a61940e7 100644
--- a/edit.mu
+++ b/edit.mu
@@ -83,6 +83,7 @@ recipe new-editor [
   *y <- copy *init
   # initial render to screen, just for some old tests
   _, screen <- render screen, result
+  +editor-initialization
   reply result
 ]
 
@@ -1017,7 +1018,16 @@ scenario editor-wraps-cursor-after-inserting-characters-2 [
   ]
 ]
 
-# if newline, move cursor to start of next line
+# if newline, move cursor to start of next line, and maybe align indent with previous line
+
+container editor-data [
+  indent:boolean
+]
+
+after +editor-initialization [
+  indent:address:boolean <- get-address *result, indent:offset
+  *indent <- copy 1/true
+]
 
 scenario editor-moves-cursor-down-after-inserting-newline [
   assume-screen 10/width, 5/height
@@ -1052,6 +1062,8 @@ after +insert-character-special-case [
       *cursor-row <- subtract *cursor-row, 1  # bring back into screen range
     }
     # indent if necessary
+    indent?:boolean <- get *editor, indent:offset
+    reply-unless indent?
     d:address:duplex-list <- get *editor, data:offset
     end-of-previous-line:address:duplex-list <- prev-duplex *before-cursor
     indent:number <- line-indent end-of-previous-line, d
@@ -1173,6 +1185,52 @@ ef]
   ]
 ]
 
+scenario editor-skips-indent-around-paste [
+  assume-screen 10/width, 10/height
+  1:address:array:character <- new [ab
+  cd
+ef]
+  2:address:editor-data <- new-editor 1:address:array:character, screen:address, 0/left, 10/right
+  # position cursor after 'cd' and hit 'newline' surrounded by paste markers
+  assume-console [
+    left-click 2, 8
+    press 65507  # start paste
+    type [
+]
+    press 65506  # end paste
+  ]
+  run [
+    editor-event-loop screen:address, console:address, 2:address:editor-data
+    3:number <- get *2:address:editor-data, cursor-row:offset
+    4:number <- get *2:address:editor-data, cursor-column:offset
+  ]
+  # cursor should be below start of previous line
+  memory-should-contain [
+    3 <- 3  # cursor row
+    4 <- 0  # cursor column (not indented)
+  ]
+]
+
+after +handle-special-key [
+  {
+    paste-start?:boolean <- equal *k, 65507/paste-start
+    break-unless paste-start?
+    indent:address:boolean <- get-address *editor, indent:offset
+    *indent <- copy 0/false
+    reply
+  }
+]
+
+after +handle-special-key [
+  {
+    paste-end?:boolean <- equal *k, 65506/paste-end
+    break-unless paste-end?
+    indent:address:boolean <- get-address *editor, indent:offset
+    *indent <- copy 1/true
+    reply
+  }
+]
+
 ## special shortcuts for manipulating the editor
 # Some keys on the keyboard generate unicode characters, others generate
 # terminfo key codes. We need to modify different places in the two cases.
@@ -3765,6 +3823,7 @@ recipe new-programming-environment [
   current-sandbox:address:address:editor-data <- get-address *result, current-sandbox:offset
   *current-sandbox <- new-editor initial-sandbox-contents, screen, new-left, width/right
   screen <- render-all screen, result
+  +programming-environment-initialization
   reply result
 ]