Merge text0
This commit is contained in:
commit
47dd4a6785
46
text.lua
46
text.lua
|
@ -27,31 +27,45 @@ function Text.draw(State, line_index, y, startpos, fg, hide_cursor)
|
|||
local screen_line = Text.screen_line(line, line_cache, i)
|
||||
--? print('text.draw:', screen_line, 'at', line_index,pos, 'after', x,y)
|
||||
local frag_len = utf8.len(screen_line)
|
||||
-- render fragment
|
||||
-- render any highlights
|
||||
if State.selection1.line then
|
||||
local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
|
||||
Text.draw_highlight(State, line, State.left,y, pos, lo,hi)
|
||||
end
|
||||
App.color(Text_color)
|
||||
App.screen.print(screen_line, State.left,y)
|
||||
-- render cursor if necessary
|
||||
if line_index == State.cursor1.line then
|
||||
if pos <= State.cursor1.pos and pos + frag_len >= State.cursor1.pos then
|
||||
if State.search_term then
|
||||
local data = State.lines[State.cursor1.line].data
|
||||
local cursor_offset = Text.offset(data, State.cursor1.pos)
|
||||
if data:sub(cursor_offset, cursor_offset+#State.search_term-1) == State.search_term then
|
||||
local lo_px = Text.draw_highlight(State, line, State.left,y, pos, State.cursor1.pos, State.cursor1.pos+utf8.len(State.search_term))
|
||||
App.color(fg)
|
||||
love.graphics.print(State.search_term, State.left+lo_px,y)
|
||||
-- render search highlight or cursor
|
||||
if State.search_term then
|
||||
local data = State.lines[State.cursor1.line].data
|
||||
local cursor_offset = Text.offset(data, State.cursor1.pos)
|
||||
if data:sub(cursor_offset, cursor_offset+#State.search_term-1) == State.search_term then
|
||||
local save_selection = State.selection1
|
||||
State.selection1 = {line=line_index, pos=State.cursor1.pos+utf8.len(State.search_term)}
|
||||
local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
|
||||
Text.draw_highlight(State, line, State.left,y, pos, lo,hi)
|
||||
State.selection1 = save_selection
|
||||
end
|
||||
else
|
||||
if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then
|
||||
if hide_cursor then
|
||||
Text.pretend_draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
|
||||
else
|
||||
Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y, Cursor_color, fg)
|
||||
end
|
||||
elseif pos + frag_len == State.cursor1.pos then
|
||||
-- Show cursor at end of line.
|
||||
-- This place also catches end of wrapping screen lines. That doesn't seem worth distinguishing.
|
||||
-- It seems useful to see a cursor whether your eye is on the left or right margin.
|
||||
if hide_cursor then
|
||||
Text.pretend_draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
|
||||
else
|
||||
Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y, Cursor_color, fg)
|
||||
end
|
||||
elseif hide_cursor then
|
||||
Text.pretend_draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y)
|
||||
else
|
||||
Text.draw_cursor(State, State.left+Text.x(screen_line, State.cursor1.pos-pos+1), y, Cursor_color, fg)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- render fragment
|
||||
App.color(Text_color)
|
||||
App.screen.print(screen_line, State.left,y)
|
||||
y = y + State.line_height
|
||||
if y >= App.screen.height then
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue