From 63f59e7c2cda73ec6e932249523723c6fb970a11 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 2 Jun 2022 19:28:38 -0700 Subject: scroll if necessary on paste --- text.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'text.lua') diff --git a/text.lua b/text.lua index e8b4b24..c397ff3 100644 --- a/text.lua +++ b/text.lua @@ -1435,17 +1435,40 @@ function Text.keychord_pressed(chord) App.setClipboardText(s) end elseif chord == 'M-v' then + -- 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 = Cursor1.line local before = snapshot(before_line) local clipboard_data = App.getClipboardText() + local num_newlines = 0 -- hack 1 for _,code in utf8.codes(clipboard_data) do local c = utf8.char(code) if c == '\n' then Text.insert_return() + num_newlines = num_newlines+1 else Text.insert_at_cursor(utf8.char(code)) end end + -- hack 1: if we have too many newlines we definitely need to scroll + for i=before_line,Cursor1.line do + Lines[i].screen_line_starting_pos = nil + Text.populate_screen_line_starting_pos(i) + end + if Cursor1.line-Screen_top1.line+1 + num_newlines > App.screen.height/math.floor(15*Zoom) then + Screen_top1.line = Cursor1.line + Screen_top1.pos = 1 + Text.scroll_up_while_cursor_on_screen() + end + -- hack 2: if we have too much text wrapping we definitely need to scroll + local clipboard_text = App.newText(love.graphics.getFont(), clipboard_data) + local clipboard_width = App.width(clipboard_text) +--? print(Cursor_y, Cursor_y*Line_width, Cursor_y*Line_width+Cursor_x, Cursor_y*Line_width+Cursor_x+clipboard_width, Line_width*App.screen.height/math.floor(15*Zoom)) + if Cursor_y*Line_width+Cursor_x + clipboard_width > Line_width*App.screen.height/math.floor(15*Zoom) then + Screen_top1.line = Cursor1.line + Screen_top1.pos = 1 + Text.scroll_up_while_cursor_on_screen() + end record_undo_event({before=before, after=snapshot(before_line, Cursor1.line)}) --== shortcuts that move the cursor elseif chord == 'left' then -- cgit 1.4.1-2-gfad0 danisanti/profani-tty/tree/?id=c06643001ec16107b66ff72f134eefbc7feca9f0'>root/themes/bios
blob: a0a36eb8ef57cca24a85e0f26d45efb16e5877f9 (plain) (blame)
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