AT3LVCMPK7SSIEHF3JI6XTA5XNO7HFI3AOHYNX4Y24QKJ2NS6DDQC
RXNR3U5EC64CNAS7WXGTJBUCOMFCYS5TMBM4BG7D7XOPVAJPDY3AC
VO2ZVTWKGVKKIU6IM2SKMYKLK4FKR2VYJYMYP5TEAFGMS7TKEDIQC
SCOXD4EOOL76VOGQSSNYDQS4IPXJTQ7FABDLG66GLLNREYRZF5CQC
R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC
JOPVPUSAMMU6RFVDQR4NJC4GNNUFB7GPKVH7OS5FKCYS5QZ53VLQC
D4B52CQ2QKG2HQKFUQOO5S2ME325DTW3PH2D7SBXCW4BPQFYG7CAC
36Z442IVPXHZ7D2QI26YLN3TDDEMDRQ2GKBYQAD6NUHQZVCCY4VAC
UEE5W7WJ46FIBN4ZH45Z33L4RYXK5AP5ZIBHYTFOJTDWVVX54QKAC
BH7BT36LM3D7HF3GOHXUPVNKLJ5LFJHOHRLD3KTC5HA627M3II4AC
FS2ITYYHBLFT66YUC3ENPFYI2HOYHOVEPQIN7NQR6KF5MEK4NKZAC
elseif chord == 'C-a' then
State.selection1 = {line=1, pos=1}
State.cursor1 = {line=#State.lines, pos=utf8.len(State.lines[#State.lines].data)+1, posB=nil}
elseif chord == 'C-c' then
local s = Text.selection(State)
if s then
App.setClipboardText(s)
end
elseif chord == 'C-x' then
for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll
local s = Text.cut_selection(State, State.left, State.right)
if s then
App.setClipboardText(s)
end
schedule_save(State)
elseif chord == 'C-v' then
for _,line_cache in ipairs(State.line_cache) do line_cache.starty = nil end -- just in case we scroll
-- We don't have a good sense of when to scroll, so we'll be conservative
-- and sometimes scroll when we didn't quite need to.
local before_line = State.cursor1.line
local before = snapshot(State, before_line)
local clipboard_data = App.getClipboardText()
for _,code in utf8.codes(clipboard_data) do
local c = utf8.char(code)
if c == '\n' then
Text.insert_return(State)
else
Text.insert_at_cursor(State, c)
end
end
if Text.cursor_out_of_screen(State) then
Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
end
schedule_save(State)
record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)})
chord ~= 'C-a' and chord ~= 'C-c' and chord ~= 'C-x' and chord ~= 'backspace' and backspace ~= 'delete' and not App.is_cursor_movement(chord) then
Text.delete_selection(State, State.left, State.right)
end
if edge.suffix and rfind(frag, edge.suffix, nil, --[[plain]] true) == #frag - #edge.suffix + 1 then
Current_state = edge.target
break
end
end
end
function trim(s)
return s:gsub('^%s+', ''):gsub('%s+$', '')
end
function ltrim(s)
return s:gsub('^%s+', '')
end
function rtrim(s)
return s:gsub('%s+$', '')
end
dstring=String_color,
block_string=String_color,
block_comment=Comment_color,
}
Current_state = 'normal'
function initialize_color()
--? print('new line')
Current_state = 'normal'
end
function select_color(frag)
--? print('before', '^'..frag..'$', Current_state)
switch_color_based_on_prefix(frag)
--? print('using color', Current_state, Colors[Current_state])
App.color(Colors[Current_state])
switch_color_based_on_suffix(frag)
--? print('state after suffix', Current_state)
end
function switch_color_based_on_prefix(frag)
if Next_state[Current_state] == nil then
return
end
frag = rtrim(frag)
for _,edge in pairs(Next_state[Current_state]) do
if edge.prefix and find(frag, edge.prefix, nil, --[[plain]] true) == 1 then
Current_state = edge.target
break
end
end
end
function switch_color_based_on_suffix(frag)
if Next_state[Current_state] == nil then
return
end
frag = rtrim(frag)
for _,edge in pairs(Next_state[Current_state]) do
comment=Comment_color,
sstring=String_color,
Comment_color = {r=0, g=0, b=1}
String_color = {r=0, g=0.5, b=0.5}
Divider_color = {r=0.7, g=0.7, b=0.7}
Colors = {
normal=Text_color,
block_string={
{suffix=']]', target='normal'},
},
block_comment={
{suffix=']]', target='normal'},
},
-- comments are a sink
}
{prefix='[[', target='block_string'}, -- only single line for now
},
dstring={
{suffix='"', target='normal'},
},
sstring={
{suffix="'", target='normal'},
},
{prefix='--[[', target='block_comment'}, -- only single-line for now
{prefix='--', target='comment'},
{prefix='"', target='dstring'},
{prefix="'", target='sstring'},