-
Notifications
You must be signed in to change notification settings - Fork 0
/
vi.lua
1918 lines (1710 loc) · 50.8 KB
/
vi.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
--- Made in a day based on the built in edit.lua in CC: Tweaked
--- Though unlike edit.lua this features most text manipulation features in the original vi
--- Some of these include undo, redo, clipboard and normal mode commands like w b e l k j h p yy dd
---
--- Please note! To exit NORMAL mode you need to use CTRL+C since ESC closes the gui in CC:Tweaked
---
--- By Walcriz in June 2024
--- Based off (https://github.com/cc-tweaked/CC-Tweaked/blob/mc-1.20.x/projects/core/src/main/resources/data/computercraft/lua/rom/programs/edit.lua) with CCPL license (2017 Daniel Ratcliffe)
---
---@diagnostic disable: redefined-local
-- Get the file to edit
local terminalArgs = { ... }
if #terminalArgs == 0 then
local programName = arg[0] or fs.getName(shell.getRunningProgram())
print("Usage: " .. programName .. " <path>")
return
end
-- Check the file exists and is not a directory
local path = shell.resolve(terminalArgs[1])
local readOnly = fs.isReadOnly(path)
if fs.exists(path) and fs.isDir(path) then
print("Cannot edit a directory.")
return
end
-- Create .lua files by default
if not fs.exists(path) and not string.find(path, "%.") then
local extension = settings.get("edit.default_extension")
if extension ~= "" and type(extension) == "string" then
path = path .. "." .. extension
end
end
local modes = {
insert = "INSERT",
normal = "NORMAL",
visual = "VISUAL",
vline = "V-LINE",
command = "COMMAND",
search = "SEARCH",
}
-- Setup
local x, y = 1, 1
local w, h = term.getSize()
local scrollX, scrollY = 0, 0
local mode = modes.normal
local dirty = false
local unsaved = false
local completionDirty = false
local preferredX = nil
local visual_x, visual_y
local prompt = nil
local search = {
searching = false,
current = 0,
results = nil
}
local clipboard = {
---@type "text"|"line"|""
type = "",
---@type string|table
text = ""
}
local commandX = 1
local commandText = ""
local commandHistory = {
history = {},
current = 0
}
-- Keys
local ctrlDown = false
-- Used to keep track of how far into an action you are for multi character actions
local actionProgress = {}
local lines = {}
local running = true
local undo_states = {}
local redo_states = {}
-- Colours
local highlightColour, keywordColour, commentColour, textColour, bgColour, stringColour, errorColour, selectionColour
if term.isColour() then
bgColour = colours.black
textColour = colours.white
highlightColour = colours.yellow
keywordColour = colours.yellow
commentColour = colours.green
stringColour = colours.red
errorColour = colours.red
selectionColour = colours.grey
else
bgColour = colours.black
textColour = colours.white
highlightColour = colours.lightGrey
keywordColour = colours.lightGrey
commentColour = colours.grey
stringColour = colours.white
errorColour = colours.white
selectionColour = colours.lightGrey
end
-- Status/language server info
local status = { ok = true, text = "" }
local function setStatus(text, ok)
status.text = text
status.ok = ok
end
if readOnly then
setStatus("File is read only", false)
elseif fs.getFreeSpace(path) < 1024 then
setStatus("Disk is low on space", false)
else
setStatus(mode, true)
end
-- Utilites
local function load(_path)
lines = {}
if fs.exists(_path) then
local file = io.open(_path, "r")
local sLine = file:read()
while sLine do
table.insert(lines, sLine)
sLine = file:read()
end
file:close()
end
if #lines == 0 then
table.insert(lines, "")
end
end
local function save(_path, _writer)
-- Create intervening folder
local sDir = _path:sub(1, _path:len() - fs.getName(_path):len())
if not fs.exists(sDir) then
fs.makeDir(sDir)
end
-- Save
local file, fileerr
local function innerSave()
file, fileerr = fs.open(_path, "w")
if file then
if file then
_writer(file)
end
else
error("Failed to open " .. _path)
end
end
local ok, err = pcall(innerSave)
if file then
file.close()
end
return ok, err, fileerr
end
function table.shallow_copy(t)
local t2 = {}
for k,v in pairs(t) do
t2[k] = v
end
return t2
end
function table.merge(t1, t2)
for k,v in pairs(t2) do
t1[k] = v
end
return t1
end
local function getSelectedText() -- TODO: FIX THIS, IT IS VERY BORKEN
local selectedLines = {}
if mode == modes.vline then
local upper = math.min(y, y + visual_y - 1)
local lower = math.max(y, y + visual_y - 1)
for i = upper, lower do
selectedLines[#selectedLines + 1] = lines[i]
end
elseif mode == modes.visual then
local currX, currY = x, y
if currY > visual_y then
local tempX, tempY = currX, currY
currX, currY = visual_x, visual_y
visual_x, visual_y = tempX, tempY
end
if currY == visual_y then
if currX > visual_x then
local temp = currX
currX = visual_x
visual_x = temp
end
selectedLines[1] = string.sub(lines[currY], currX, visual_x)
else
-- First and last line in selection needs special treatment
selectedLines[1] = string.sub(lines[currY], currX)
for i = currY + 1, visual_y - 1 do
selectedLines[#selectedLines + 1] = lines[i]
end
selectedLines[#selectedLines + 1] = string.sub(lines[visual_y], 1, visual_x)
end
end
return selectedLines
end
local function insideSelection(x, y) -- TODO: FIX THIS, IT IS VERY BORKEN
if mode == modes.vline then
local upper = math.min(y, visual_y)
local lower = math.max(y, visual_y)
return y >= upper and y <= lower
elseif mode == modes.visual then
local currX, currY = x, y
if currY > visual_y then
local tempX, tempY = currX, currY
currX, currY = visual_x, visual_y
visual_x, visual_y = tempX, tempY
end
if currY == visual_y then
if currX > visual_x then
local temp = currX
currX = visual_x
visual_x = temp
end
return currX <= x and x <= visual_x
else
-- First and last line in selection needs special treatment
end
else
return false
end
end
local keywords = {
["and"] = true,
["break"] = true,
["do"] = true,
["else"] = true,
["elseif"] = true,
["end"] = true,
["false"] = true,
["for"] = true,
["function"] = true,
["if"] = true,
["in"] = true,
["local"] = true,
["nil"] = true,
["not"] = true,
["or"] = true,
["repeat"] = true,
["return"] = true,
["then"] = true,
["true"] = true,
["until"] = true,
["while"] = true,
["goto"] = true
}
local written = 0
local function tryWrite(index, line, regex, colour)
local match = string.match(line, regex)
if match then
if type(colour) == "number" then
term.setTextColour(colour)
else
term.setTextColour(colour(match))
end
for k = 1, #match do
local char = match:sub(k,k)
if insideSelection(index, written + k - 1) then
term.setBackgroundColour(selectionColour)
end
term.write(char)
term.setBackgroundColour(bgColour)
end
-- term.write(match)
term.setTextColour(textColour)
written = written + #match + 1
return string.sub(line, #match + 1)
end
return nil
end
local function writeHighlighted(line, index)
written = 0
while #line > 0 do
line =
tryWrite(index, line, "^%-%-%[%[.-%]%]", commentColour) or
tryWrite(index, line, "^%-%-.*", commentColour) or
tryWrite(index, line, "^\"\"", stringColour) or
tryWrite(index, line, "^\".-[^\\]\"", stringColour) or
tryWrite(index, line, "^\'\'", stringColour) or
tryWrite(index, line, "^\'.-[^\\]\'", stringColour) or
tryWrite(index, line, "^%[%[.-%]%]", stringColour) or
tryWrite(index, line, "^[%w_]+", function(match)
if keywords[match] then
return keywordColour
end
return textColour
end) or
tryWrite(index, line, "^[^%w_]", textColour)
end
end
-- Tab Completions
local tabCompletions
local currentCompletion
local tabCompleteEnv = _ENV
local function writeCompletion()
if currentCompletion then
local completion = tabCompletions[currentCompletion]
term.setTextColor(colours.white)
term.setBackgroundColor(colours.grey)
term.write(completion)
term.setTextColor(textColour)
term.setBackgroundColor(bgColour)
end
end
local function redrawText()
local cursorX, cursorY = x, y
for y = 1, h - 1 do
term.setCursorPos(1 - scrollX, y)
term.clearLine()
local sLine = lines[y + scrollY]
if sLine ~= nil then
writeHighlighted(sLine, y + scrollY)
if cursorY == y and cursorX == #sLine + 1 then
writeCompletion()
end
end
end
term.setCursorPos(x - scrollX, y - scrollY)
end
-- Find words in lines and append it to the tabCompletions
local function findWordsInLines(match)
if #match < 2 then
return
end
currentCompletion = nil
for index, line in ipairs(lines) do
if index == y then
goto continue
end
for word in line:gmatch("%w+") do
-- Word must start with match
if not match or word:sub(1, #match) == match then
table.insert(tabCompletions, string.sub(word, #match + 1))
end
end
::continue::
end
end
local function complete(line)
if settings.get("edit.autocomplete") then
local startPos = string.find(line, "[a-zA-Z0-9_%.:]+$")
if startPos then
line = string.sub(line, startPos)
end
if #line > 0 then
tabCompletions = textutils.complete(line, tabCompleteEnv)
-- Append findWordsInLines results to tabCompletions
findWordsInLines(line)
return tabCompletions
end
end
return nil
end
local function recomplete()
local line = lines[y]
if not readOnly and x == #line + 1 then
tabCompletions = complete(line)
if tabCompletions and #tabCompletions > 0 then
currentCompletion = 1
else
currentCompletion = nil
end
else
tabCompletions = nil
currentCompletion = nil
end
end
local function redrawLine(_nY)
local sLine = lines[_nY]
if sLine then
term.setCursorPos(1 - scrollX, _nY - scrollY)
term.clearLine()
writeHighlighted(sLine, _nY)
if _nY == y and x == #sLine + 1 then
writeCompletion()
end
term.setCursorPos(x - scrollX, _nY - scrollY)
end
end
local function stringifyAction()
local text = ""
for _, value in ipairs(actionProgress) do
if type(value) == "string" then
text = text .. value
elseif type(value) == "number" then
text = "<" .. value .. ">"
end
-- setStatus("Going deeper ..>> " .. type(value) .. " <<>> " .. #actionText, true)
end
return text
end
-- Command line
local function redrawCommandLine()
-- Clear line
term.setCursorPos(1, h)
term.clearLine()
if mode == modes.command then
if prompt then
term.write(prompt.text)
return
end
-- Draw
term.setTextColour(textColour)
term.write(search.searching and "/" or ":")
term.write(commandText)
term.setCursorPos(commandX + 1, h)
else
-- Draw status
term.setTextColour(status.ok and highlightColour or errorColour)
term.write(status.text)
term.setTextColour(textColour)
-- Draw line numbers
local actionReadable = stringifyAction()
term.setCursorPos(w - #("Ln " .. y) - #(actionReadable .. " ") + 1, h)
term.setTextColour(textColour)
term.write(actionReadable .. " ")
term.setTextColour(highlightColour)
term.write("Ln ")
term.setTextColour(textColour)
term.write(y)
-- Reset cursor
term.setCursorPos(x - scrollX, y - scrollY)
end
end
local function setPrompt(text, buttons)
if text == nil then
mode = modes.normal
prompt = nil
redrawCommandLine()
return
end
prompt = {
text = text,
buttons = buttons,
}
mode = modes.command
redrawCommandLine()
end
local commands
commands = {
["w"] = function() -- Save
if readOnly then
setStatus("Access denied", false)
else
local ok, _, fileerr = save(path, function(file)
for _, line in ipairs(lines) do
file.write(line .. "\n")
end
end)
if ok then
setStatus("Saved to " .. path, true)
else
if fileerr then
setStatus("Error saving: " .. fileerr, false)
else
setStatus("Error saving to " .. path, false)
end
end
unsaved = false
end
redrawCommandLine()
end,
["q"] = function() -- Quit
if #undo_states > 0 and not readOnly and unsaved then
setPrompt("Save changes? [Y]es [N]o [C]ancel", {
y = function()
commands["w"]()
running = false
end,
n = function()
running = false
end,
c = function()
setPrompt(nil)
end
})
else
running = false
end
end,
["wq"] = function() -- Save and quit
commands["w"]()
commands["q"]()
end,
}
local function setCursor(newX, newY)
if newY > #lines then
newY = #lines
end
if newY < 1 then
newY = 1
end
-- try to maintain x when changing y via preferredX
-- TODO: Fix
if preferredX and newX < preferredX and newY ~= y then
newX = preferredX
preferredX = nil
elseif not preferredX and newX < x then
preferredX = newX
end
if mode == modes.insert then
if newX > #lines[newY] + 1 then
newX = #lines[newY] + 1
end
else
if newX > #lines[newY] then
newX = #lines[newY]
end
end
if newX < 1 then
newX = 1
end
local _, oldY = x, y
x, y = newX, newY
local screenX = x - scrollX
local screenY = y - scrollY
local redraw = false
if screenX < 1 then
scrollX = x - 1
screenX = 1
redraw = true
elseif screenX > w then
scrollX = x - w
screenX = w
redraw = true
end
if screenY < 1 then
scrollY = y - 1
screenY = 1
redraw = true
elseif screenY > h - 1 then
scrollY = y - (h - 1)
screenY = h - 1
redraw = true
end
if mode == modes.visual or mode == modes.vline then
redrawText()
else
recomplete()
if redraw then
redrawText()
elseif y ~= oldY then
redrawLine(oldY)
redrawLine(y)
else
redrawLine(y)
end
end
term.setCursorPos(screenX, screenY)
redrawCommandLine()
end
---Yank text to the clipboard
---@param text string|table
---@param type "text"|"line"
local function yank(text, type)
clipboard = {
type = type,
text = text
}
end
local function snapshot()
unsaved = true
if mode == modes.insert then
dirty = true
end
undo_states[#undo_states + 1] = {
x = x,
y = y,
lines = table.shallow_copy(lines)
}
end
---Paste clipboard
---@param direction "up"|"down"
local function paste(direction)
snapshot()
if clipboard.type == "line" then
if direction == "up" then
if type(clipboard.text) == "table" then
for _, line in ipairs(clipboard.text) do -- TODO: this needs to be reversed
table.insert(lines, y, line)
end
else
table.insert(lines, y, clipboard.text)
end
else
if type(clipboard.text) == "table" then
for _, line in ipairs(clipboard.text) do
table.insert(lines, y + 1, line)
setCursor(x, y + 1)
end
else
table.insert(lines, y + 1, clipboard.text)
setCursor(x, y + 1)
end
end
elseif clipboard.type == "text" then
-- Insert text into current line
lines[y] = string.sub(lines[y], 1, x) .. clipboard.text .. string.sub(lines[y], x + 1)
setCursor(x + #clipboard.text, y)
end
redrawText()
end
local function undo()
if #undo_states > 0 then
redo_states[#redo_states + 1] = {
x = x,
y = y,
lines = table.shallow_copy(lines)
}
local state = undo_states[#undo_states]
lines = table.shallow_copy(state.lines)
undo_states[#undo_states] = nil
setCursor(state.x, state.y)
end
end
local function redo()
if #redo_states > 0 then
undo_states[#undo_states + 1] = {
x = x,
y = y,
lines = table.shallow_copy(lines)
}
local state = redo_states[#redo_states]
lines = table.shallow_copy(state.lines)
redo_states[#redo_states] = nil
end
end
local function isAtEndOfFile()
return y == #lines and x == #lines[y]
end
local function isJumpStop(char)
return char == "(" or char == ")"
or char == "[" or char == "]"
or char == "{" or char == "}"
or char == "<" or char == ">"
or char == "|"
or char == ","
or char == ";"
or char == ":"
or char == "."
or char == "?"
or char == "/"
or char == "\\"
or char == "*"
or char == "+"
or char == "-"
or char == "="
end
local function searchAndReplace(pattern)
local prefix, search, replace, suffix = pattern:match("^(%%?s)/(.-)/(.-)/?(g?)$")
if not prefix then
setStatus("Invalid pattern format")
redrawCommandLine()
return
end
snapshot()
-- Helper function to replace the first occurrence
local function replaceFirst(str, search, replace)
local startPos, endPos = str:find(search)
if not startPos then
return str
end
return str:sub(1, startPos - 1) .. replace .. str:sub(endPos + 1)
end
-- Helper function to replace all occurrences
local function replaceAll(str, search, replace)
return str:gsub(search, replace)
end
if prefix == "%s" then
-- Replace on all lines
for i = 1, #lines do
if suffix == "g" then
lines[i] = replaceAll(lines[i], search, replace)
else
lines[i] = replaceFirst(lines[i], search, replace)
end
end
redrawText()
else
-- Replace on the current line
if suffix == "g" then
lines[y] = replaceAll(lines[y], search, replace)
else
lines[y] = replaceFirst(lines[y], search, replace)
end
redrawLine(y)
end
end
function search:searchLines(text)
text = string.gsub(text, "%(", "%%(")
text = string.gsub(text, "%)", "%%)")
text = string.gsub(text, "%[", "%%[")
text = string.gsub(text, "%]", "%%]")
search.results = {}
local current = 1
for i = 1, #lines do
local s
local function find()
s, _ = string.find(lines[i], text)
end
if not pcall(find) then
setStatus("Invalid lua pattern!", false)
redrawCommandLine()
return true
end
if s then
search.results[#search.results + 1] = { y = i, x = s }
if ((y == i and x < s) or i > y) and current == 1 then
current = #search.results
end
end
end
if #search.results == 0 then
search.results = nil
else
search.current = current
end
return false
end
function search:next()
if search.results then
search.current = search.current + 1
if search.current > #search.results then
search.current = 1
end
y = search.results[search.current].y
x = search.results[search.current].x
setCursor(x, y)
end
end
function search:previous()
if search.results then
search.current = search.current - 1
if search.current < 1 then
search.current = #search.results
end
y = search.results[search.current].y
x = search.results[search.current].x
setCursor(x, y)
end
end
function commandHistory:next()
if #self.history > 0 then
self.current = self.current + 1
if self.current > #self.history then
self.current = 0
end
if self.current == 0 then
commandText = ""
else
commandText = self.history[self.current]
end
commandX = #commandText + 1
redrawCommandLine()
end
end
function commandHistory:previous()
if #self.history > 0 then
self.current = self.current - 1
if self.current < 0 then
self.current = #self.history
end
if self.current == 0 then
commandText = ""
else
commandText = self.history[self.current]
end
commandX = #commandText + 1
redrawCommandLine()
end
end
function commandHistory:append(text)
if text ~= "" and self.history[#self.history] ~= text then
self.history[#self.history + 1] = text
end
self.current = 0
end
local function getNextWord()
local wasSpace = false
local cut = string.sub(lines[y], x + 1, x + 1)
local startX = x
local endX = x
if string.sub(lines[y], x, x) == " " then
wasSpace = true
while string.sub(lines[y], endX + 2, endX + 2) == " " do
endX = endX + 1
end
end
while true do
if wasSpace and cut ~= " " then
break
end
if isJumpStop(cut) and startX ~= endX then
break
end
if isAtEndOfFile() then
break
end
if endX >= #lines[y] then
break
else
endX = endX + 1
if cut == " " then
wasSpace = true
end
end
cut = string.sub(lines[y], endX + 1, endX + 1)
end
return startX, endX
end
local function getPreviousWord()
local cut = string.sub(lines[y], x - 1, x - 1)
local startX = x - 1
local endX = x - 1
if cut == " " then
startX = startX - 1
cut = string.sub(lines[y], x - 1, x - 1)
end
while true do
if cut == " " then
break
end
if isJumpStop(cut) and startX ~= endX then
break
end
if startX == 1 then
break
else
startX = startX - 1
end
cut = string.sub(lines[y], startX - 1, startX - 1)
end
return startX, endX
end
local function getNextEndOfWord()
local cut = string.sub(lines[y], x + 1, x + 1)
local startX = x
local endX = x
if cut == " " then
endX = endX + 1
cut = string.sub(lines[y], endX + 1, endX + 1)
end
while true do
if cut == " " then
break
end
if isJumpStop(cut) and startX ~= endX then
break
end
if isAtEndOfFile() then
break
end
if endX >= #lines[y] then
break
else
endX = endX + 1
end
cut = string.sub(lines[y], endX + 1, endX + 1)
end
setStatus("Yanked: start: " .. startX .. " end: " .. endX, true)
redrawCommandLine()
return startX, endX
end
local function acceptCompletion()
if currentCompletion then
-- Append the completion
local completion = tabCompletions[currentCompletion]
lines[y] = lines[y] .. completion
setCursor(x + #completion , y)
end
end
local movement_actions = {
-- Movement
[ keys.left ] = function() setCursor(x - 1, y) end,
[ keys.right ] = function() setCursor(x + 1, y) end,
[ keys.up ] = function() setCursor(x, y - 1) end,
[ keys.down ] = function() setCursor(x, y + 1) end,
[ "h" ] = function() setCursor(x - 1, y) end,