Commit Graph

294 Commits

Author SHA1 Message Date
Kartik K. Agaram dd899d2096 standardize scroll check in a few places
I'm taking some lessons from pensieve.love here. It seem like specific
pixel thresholds don't matter too much for plain lines.love.

I'd probably feel safer if I just used Text.cursor_out_of_screen in
these places, but it means we draw the screen twice for most events[1].
Let's see if we can get by with the current approach.

[1] Or we have to start scheduling things for the next draw, which is
more complex to orchestrate.
2022-08-17 09:40:44 -07:00
Kartik K. Agaram f029c710b5 simplify cursor-on-screen check 2022-08-17 09:36:17 -07:00
Kartik K. Agaram 1d710912cc swap return values 2022-08-17 09:10:52 -07:00
Kartik K. Agaram 4f128f39f3 obsolete comment 2022-08-16 13:38:10 -07:00
Kartik K. Agaram eba973369e move 2022-08-15 16:07:32 -07:00
Kartik K. Agaram 333a0318d9 drop some unnecessary calls 2022-08-15 15:48:44 -07:00
Kartik K. Agaram 9e0cd4ad4c stop confusingly reading a global
The way Text.draw is called by edit.draw, we know it'll never be called
for lines above screen_top1.line. Comparing every line on screen with
screen_top1 makes no sense. The intent is really just to compare with
screen_top1 only for the first line, and otherwise to ignore this check.
2022-08-15 15:45:02 -07:00
Kartik K. Agaram d14e03d706 bugfix: handle drawings when updating screen top 2022-08-11 19:35:12 -07:00
Kartik K. Agaram 9ac68d710b rename 2022-08-11 19:34:18 -07:00
Kartik K. Agaram da34fabf72 bugfix: pagedown was sometimes bouncing up 2022-08-10 22:56:10 -07:00
Kartik K. Agaram ba48aadaa7 bugfix: backspace from start of final line 2022-08-10 22:38:10 -07:00
Kartik K. Agaram 8cfffdef41 unnecessary args 2022-08-10 22:29:39 -07:00
Kartik K. Agaram 0218980add click to the left of a line 2022-07-29 14:38:45 -07:00
Kartik K. Agaram 0251b3f0c2 bugfix: search
Broken since commit 188bbc73 9 days ago :/ At least we have a test for
it now.
2022-07-21 16:55:05 -07:00
Kartik K. Agaram d61b5dfdeb use line cache for drawings as well 2022-07-20 16:34:09 -07:00
Kartik K. Agaram e2734cd572 bugfix: where cursor is drawn
The published version of lines.love was broken for almost an hour. The
cursor would render one position to the right of where it really is. To
fix it, this commit rolls back 26ba6e4e5a. There doesn't seem a good
way to test it.
2022-07-20 09:11:29 -07:00
Kartik K. Agaram 88013000fc . 2022-07-20 07:50:33 -07:00
Kartik K. Agaram 9f4b41d829 exclude left margin from my word-split heuristic
Gratifying how few tests need changing. Recent commits seem on the right
track.
2022-07-20 07:15:46 -07:00
Kartik K. Agaram a472d218f2 allow Text.nearest_pos_less_than to return 0
This eliminates another case of overflowing margins.
2022-07-20 07:08:28 -07:00
Kartik K. Agaram 7dc47edde8 drop an unnecessary level of indent 2022-07-20 07:03:33 -07:00
Kartik K. Agaram 39f71784c9 clean up some prints
(Looking at prints in Text.draw, Text.compute_fragments and
Text.nearest_pos_less_than)
2022-07-20 07:00:39 -07:00
Kartik K. Agaram b5451e4351 move a var closer to its use 2022-07-20 06:56:19 -07:00
Kartik K. Agaram d41301c1b7 more clearly skip prints before screen top 2022-07-20 06:54:03 -07:00
Kartik K. Agaram 26ba6e4e5a unify two similar functions
The cost is just having to tweak a few more brittle tests. I can't
actually perceive any difference in how the cursor moves when I click on
text.
2022-07-19 17:13:16 -07:00
Kartik K. Agaram efd4a8a883 keep text from overflowing right margin
I've been sloppy about this so far, and outside of tests I can't find
any examples where it matters, but it matters in a potential fork where
I'm rendering multiple columns of text.

It's unfortunate that my tests have this level of brittleness. What I'd
really like to assert in many of these changed lines is that the text
stays inside the margins and that more text would overflow margins.
2022-07-19 16:49:08 -07:00
Kartik K. Agaram 82cdd9ddd1 bugfix: couple of margin-relative computations 2022-07-17 22:29:37 -07:00
Kartik K. Agaram 29dac6a6ec separate data structure for each line's cache data
I have no idea what the performance implications of this are..
2022-07-17 21:05:01 -07:00
Kartik K. Agaram 64eed74980 keep all text cache writes inside text.lua 2022-07-17 10:06:39 -07:00
Kartik K. Agaram 4ff6de9951 switch to line index in a function
- Text.screen_line_width
2022-07-17 09:37:50 -07:00
Kartik K. Agaram 7e7f5b9256 switch to line index in a function
- Text.compute_fragments
2022-07-17 09:30:50 -07:00
Kartik K. Agaram 860cd49f67 make a function oblivious to line data structure
- Text.screen_line_index
2022-07-17 09:21:57 -07:00
Kartik K. Agaram 2859063d9d switch to line index in a function
- Text.to_pos_on_line
2022-07-17 09:19:53 -07:00
Kartik K. Agaram 6b3ddc816f switch to line index in a function
- Text.populate_screen_line_starting_pos
2022-07-17 09:14:10 -07:00
Kartik K. Agaram 48b7de4fde switch to line index in a function
- Text.in_line
2022-07-17 09:14:10 -07:00
Kartik K. Agaram b95206fd0d drop some redundant args when clearing the cache 2022-07-17 08:18:48 -07:00
Kartik K. Agaram 038f06a342 drop some redundant args from Text.draw 2022-07-17 08:00:56 -07:00
Kartik K. Agaram f61d4269f5 bring back a set of constants
It's starting to sink in that I don't want hard-coded constants inside
objects.
2022-07-16 08:48:02 -07:00
Kartik K. Agaram 70a15b3bc9 replace globals with args in a few functions
- Drawing.draw_shape
  - Drawing.draw_pending_shape
  - Drawing.in_drawing
  - Drawing.find_or_insert_point
  - Drawing.near
  - Drawing.pixels
2022-07-12 21:58:46 -07:00
Kartik K. Agaram 2ae9cacd97 deduce left/right from state where possible 2022-07-12 20:59:24 -07:00
Kartik K. Agaram 3b36093553 left/right margin -> left/right coordinates
Editor state initialization now depends on window dimensions, so we have
to more carefully orchestrate startup.
2022-07-12 20:54:50 -07:00
Kartik K. Agaram f7d4deef0c add state arg to a few functions
- Text.cursor_at_final_screen_line
  - Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary
  - Text.snap_cursor_to_bottom_of_screen
  - Text.in_line
  - Text.to_pos_on_line
  - Text.to2
  - Text.to1
  - Text.previous_screen_line
  - Text.tweak_screen_top_and_cursor
  - Text.redraw_all
2022-07-12 17:24:01 -07:00
Kartik K. Agaram 2b1889353b add state arg to a few functions
- Text.pos_at_start_of_cursor_screen_line
  - Text.cursor_past_screen_bottom
2022-07-12 17:14:14 -07:00
Kartik K. Agaram 5107df3cd0 add state arg to a few functions
- Text.left
  - Text.right
  - Text.right_without_scroll
2022-07-12 17:10:11 -07:00
Kartik K. Agaram 5b91af1a66 add state arg to a few functions
- record_undo_event
  - undo_event
  - redo_event
  - snapshot
2022-07-12 16:55:32 -07:00
Kartik K. Agaram 188bbc73cc add state arg to a few functions
- Text.draw_highlight
  - Text.clip_selection
  - Text.selection
  - Text.cut_selection
  - Text.delete_selection
  - Text.delete_selection_without_undo
  - Text.mouse_pos
  - Text.to_pos
2022-07-12 16:51:18 -07:00
Kartik K. Agaram 800a5c064a add state arg to a few functions
- Text.insert_at_cursor
  - Text.insert_return
  - Text.pageup
  - Text.pagedown
  - Text.up
  - Text.down
  - Text.start_of_line
  - Text.end_of_line
  - Text.word_left
  - Text.word_right
2022-07-12 16:39:42 -07:00
Kartik K. Agaram adeb5416c6 add state arg to Text.textinput 2022-07-12 16:33:26 -07:00
Kartik K. Agaram b7000215d8 add state arg to schedule_save 2022-07-12 16:30:41 -07:00
Kartik K. Agaram 93aca28cb3 add state arg to Text.keychord_pressed 2022-07-12 16:23:28 -07:00
Kartik K. Agaram 3874f325f8 add state arg to some functions
- Text.draw
  - Text.draw_cursor
  - Text.draw_search_bar
2022-07-12 16:20:20 -07:00
Kartik K. Agaram 8bbc1ffe34 group all editor globals
We're still accessing them through a global. But we'll change that next.
2022-07-12 15:24:56 -07:00
Kartik K. Agaram 3850fbac35 make colors easier to edit 2022-07-11 23:18:26 -07:00
Kartik K. Agaram 3dccd7f81a stop pretending globals are local
One advantage of this approach: we don't end up with multiple lexical
scopes containing duplicates of the same modules.
2022-07-11 22:11:58 -07:00
Kartik K. Agaram 6c4483976e skip multiple consecutive whitespace 2022-07-11 19:18:54 -07:00
Kartik K. Agaram bc2c14c899 support other whitespace chars in word movements 2022-07-11 18:56:19 -07:00
Kartik K. Agaram c7978ffc73 done passing left/right margins everywhere
The final step is to add them to:
  - Text.compute_fragments

Doing it carefully caught 5 call-sites that my tests didn't catch.
2022-07-08 16:32:20 -07:00
Kartik K. Agaram 62a6c335d1 add args to some functions
- Text.populate_screen_line_starting_pos
2022-07-08 16:28:20 -07:00
Kartik K. Agaram ae1a71ea46 add args to some functions
- Text.to2
2022-07-08 16:26:04 -07:00
Kartik K. Agaram 532b8dddd7 add args to some functions
- Text.previous_screen_line
2022-07-08 16:24:10 -07:00
Kartik K. Agaram 3eb89adca6 add args to some functions
- Text.snap_cursor_to_bottom_of_screen
2022-07-08 16:22:11 -07:00
Kartik K. Agaram b163f1bc51 add args to some functions
- Text.nearest_cursor_pos
2022-07-08 16:15:04 -07:00
Kartik K. Agaram 57e3aa092a add args to some functions
- Text.move_cursor_down_to_next_text_line_while_scrolling_again_if_necessary
2022-07-08 16:15:04 -07:00
Kartik K. Agaram 348c53f3ab add args to some functions
- Text.cursor_at_final_screen_line
2022-07-08 15:58:15 -07:00
Kartik K. Agaram 0106ad4b4f add args to some functions
- Text.pos_at_start_of_cursor_screen_line
2022-07-08 15:49:52 -07:00
Kartik K. Agaram abcc18002b add args to some functions
- Text.to_pos_on_line
2022-07-08 15:45:45 -07:00
Kartik K. Agaram 9fb8f25030 indent 2022-07-08 15:43:45 -07:00
Kartik K. Agaram 00c64ed6e4 add args to some functions
- Text.in_line
2022-07-08 15:37:09 -07:00
Kartik K. Agaram a27dd15c1f add args to some functions
- Text.clip_selection
  - Text.cut_selection
  - Text.delete_selection
  - Text.delete_selection_without_undo
  - Text.mouse_pos
  - Text.to_pos
2022-07-08 15:30:10 -07:00
Kartik K. Agaram 0853a030ac add args to some functions
- Text.pageup
  - Text.pagedown
  - Text.up
  - Text.down
  - Text.end_of_line
  - Text.word_left
  - Text.word_right
  - Text.left
  - Text.right
2022-07-08 15:17:12 -07:00
Kartik K. Agaram e39269b19e start passing left/right margins everywhere
I have a set of changes that passes all tests, but I'm going to commit
them very carefully to ensure I don't miss any call-sites. In this
commit I'm adding the args to:
  - Text.draw
  - Text.tweak_screen_top_and_cursor

But calls within them don't yet pass them where they should. In this
manner I'm going to progress systematically from the top down.
2022-07-08 15:12:17 -07:00
Kartik K. Agaram 8efdb898c6 rename a couple of variables 2022-07-08 14:18:23 -07:00
Kartik K. Agaram 048b6d9d3a drop an arg from a function 2022-07-08 09:44:49 -07:00
Kartik K. Agaram cff1e58cf6 switch arg for a function 2022-07-08 09:44:49 -07:00
Kartik K. Agaram 4575648c12 optimization: moving cursor to next word 2022-07-05 11:27:41 -07:00
Kartik K. Agaram f2e5c4ffee bugfix: avoid scrolling on 'end'
There's multiple ways to do this, only one of them is right, and I keep
forgetting what it is. Turn it into a method.
2022-07-05 11:27:23 -07:00
Kartik K. Agaram e839c3036a bugfix: manage screen_top and cursor when resizing 2022-07-01 11:01:20 -07:00
Kartik K. Agaram 429a42eb1c right margin 2022-06-30 22:54:34 -07:00
Kartik K. Agaram 8c7bea8f76 rip out notion of Line_width 2022-06-30 19:50:27 -07:00
Kartik K. Agaram 510b0d1dc3 bugfix: lines that aren't drawn from the start
I can't believe I didn't catch this until now. All I had to do is open
MobyDick.markdown from https://www.hogbaysoftware.com/posts/moby-dick-workout,
press page-down and click on the top screen line (or any screen line
containing the same line as the top screen line). Easy to catch with any
file containing lots of overly long lines, as happens in particular at
the start of Moby Dick.

I _had_ seen this problem before, but it seemed to disappear after
unrelated changes, and I convinced myself I'd fixed it as a side-effect.
The bug just failed to manifest if the top line happened to start at the
top of the screen. Scroll down a few pages in Moby Dick and the dialogue
starts and line length drops precipitously.
2022-06-30 18:14:48 -07:00
Kartik K. Agaram ea4aa0999c clicking to the right of a line within line width 2022-06-29 09:30:23 -07:00
Kartik K. Agaram d07a336131 . 2022-06-29 09:17:38 -07:00
Kartik K. Agaram 8d3adfa36d bugfix: clicking past end of screen line
I could swear I checked this at some point. But I didn't have a test!
2022-06-29 09:17:38 -07:00
Kartik K. Agaram b49ff8dde9 bugfix: scrolling in left/right movements
I'd always had a funny feeling there was something missing there but
somehow never thought of the right failing test.
2022-06-28 18:48:59 -07:00
Kartik K. Agaram e63878897e undo commit 861c57b533
Turns out ctrl+ makes it into lua.textinput. Thanks John Blommers for
the report. This should fix https://github.com/akkartik/lines.love/issues/6.
2022-06-27 17:32:52 -07:00
Kartik K. Agaram 2233066409 bugfix: clear selection in a couple more places 2022-06-23 12:06:44 -07:00
Kartik K. Agaram cb99ac300c fix a failing test
I deployed this without even running it once :/ Production was broken
for 9 minutes until I rolled back.
2022-06-23 11:40:00 -07:00
Kartik K. Agaram 009c7abb60 extract a function 2022-06-23 11:09:49 -07:00
Kartik K. Agaram 5a06c1286d bugfix: recompute screen lines in backspace/delete
Scenario: backspacing until a line takes up fewer screen lines, then
pressing `down`.

I've gone through and checked that fragments and screen_line_starting_pos
are now cleared together everywhere.
2022-06-23 11:03:46 -07:00
Kartik K. Agaram 54eefbbf2d turns out super- chords to get to textinput 2022-06-22 17:37:26 -07:00
Kartik K. Agaram 8e68c699f5 bugfix: delete selection before pasting 2022-06-21 09:56:04 -07:00
Kartik K. Agaram 9c8285bf08 bugfix
State changes when inserting return are now in sync with other
characters.
2022-06-21 07:24:44 -07:00
Kartik K. Agaram 5a0b6c6a58 better fix for commit 3ffc2ed8f
I'm giving up finding a more generalized solution. The issue is that we
need the correct selection state right up to the point where we modify
Lines, in order to capture precise undo state.

Hopefully there aren't any other keychords that should clear the
selection.
2022-06-20 13:30:54 -07:00
Kartik K. Agaram 0d1e6aacd9 revert selection logic to before commit 3ffc2ed8f
We still have a failing test, but now it's the one we introduced in
commit 3ffc2ed8f.
2022-06-20 13:12:29 -07:00
Kartik K. Agaram c1b6bac187 much simpler
We just need to ensure textinput events never make use of selection
state.

All tests are passing, but I'm aware of a couple of issues. But now we
can keep all the special cases in one place.
2022-06-20 11:58:26 -07:00
Kartik K. Agaram 861c57b533 some early returns should be asserts 2022-06-20 11:51:07 -07:00
Kartik K. Agaram 809dae205d move Selection1 clearing past business logic
Now all the cases that clear Selection1 do so in a very consistent way
at the end of each case. And cases that set Selection1 symmetrically do
so at the start of each case.
2022-06-20 11:35:27 -07:00
Kartik K. Agaram d90617ee24 remove some redundant checks
Now all the cases manage Selection1 similarly.
2022-06-20 11:33:04 -07:00
Kartik K. Agaram 3986e99fe0 no, that's not right
Bugfix: we want selections to persist even when we lift up the shift
key.

This requires hoisting some code inside every case inside the whole
keypress hierarchy, to ensure we never clear selections before
textinput events can handle them.

Current cross-cutting concerns we're explicitly scattering code for.
  - autosave
  - undo
  - selection management
2022-06-20 11:31:14 -07:00
Kartik K. Agaram 3ffc2ed8f3 bugfix
To reproduce:
  click to position cursor at end of a line
  hit enter
  press any key

before:
  newline got erased and key got added to previous line

now:
  newline is preserved

The new test checks a generalization of this.
2022-06-19 09:21:32 -07:00
Kartik K. Agaram 703ed905c1 bugfix: crash in Text.up() after return
Let's just make all the utf8.offset calculations more defensive.
2022-06-19 09:06:41 -07:00