From 8be21e8ed1cc43f92b838c1f1a98ad871f50945c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Cuervo?= Date: Sun, 22 Oct 2023 11:47:26 -0400 Subject: Implement ctrl+a and ctrl+e --- virtual-programs/editor.folk | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'virtual-programs') diff --git a/virtual-programs/editor.folk b/virtual-programs/editor.folk index b7f150e1..0c62f018 100644 --- a/virtual-programs/editor.folk +++ b/virtual-programs/editor.folk @@ -123,6 +123,14 @@ proc rotateStroke {points center angle} { } } +proc getLineLength {code cursor} { + set lines [split $code "\n"] + set line [lindex $lines [lindex $cursor 1]] + set ll [string length $line] + puts "linelength: $ll" + return $ll +} + proc getLineShift {lines} { set longestLineLength 0 foreach line [split $lines "\n"] { @@ -148,6 +156,7 @@ proc drawCursor {cursorPosition lineShift region} { set shiftMultiplier [list 10 10] # 20 20 scale is arbitrary, computing it off of Display or something ..... + # TODO: Pull these variables from the Display file set cursorScale [list 20 20] ;# OLD # set cursorScale [list $cursorHeight $cursorWidth] @@ -162,9 +171,6 @@ proc drawCursor {cursorPosition lineShift region} { # Calculate the final cursor position set scaledCursor [vec2::mult $cursorScale $cursorPosition] - puts "lineShiftHalf | multipliedShift | adjustedShift | shiftedAnchor | scaledCursor" - puts "$lineShiftHalf | $multipliedShift | $adjustedShift | $shiftedAnchor | $scaledCursor" - # Something is going wrong here, I think set finalCursor [add $shiftedAnchor $scaledCursor] # debug $finalCursor gold @@ -259,7 +265,6 @@ Every time keyboard claims key /currentCharacter/ is down with modifiers /modifi Claim the cursor is $cursor } default { - Claim the cursor is [updateCursor $cursor {x 1}] if {$modifier == "ctrl" & $currentCharacter == "p"} { Wish to print $code with job id [expr {rand()}] return @@ -269,6 +274,19 @@ Every time keyboard claims key /currentCharacter/ is down with modifiers /modifi Claim the cursor is [list 0 0] return } + if {$modifier == "ctrl" & $currentCharacter == "a"} { + Commit code { Claim $id has program code $code} + lassign $cursor x y + Claim the cursor is [list 0 $y] + return + } + if {$modifier == "ctrl" & $currentCharacter == "e"} { + Commit code { Claim $id has program code $code} + lassign $cursor x y + Claim the cursor is [list [getLineLength $code $cursor] $y] + return + } + Claim the cursor is [updateCursor $cursor {x 1}] Commit code { Claim $id has program code [insertCharacter $code $currentCharacter $cursor] } } } -- cgit v1.2.3