Commit Graph

43 Commits

Author SHA1 Message Date
Kartik K. Agaram 95d88a8298 use editor state font for width calculations 2024-01-12 05:23:06 -08:00
Kartik K. Agaram 8a588880b7 manually maintain mouse button press state
Just checking mouse.isDown works if the editor is the entirety of the
app, as is true in this fork. However, we often want to introduce other
widgets. We'd like tapping on them to not cause the selection to flash:
  https://news.ycombinator.com/context?id=38404923&submission=38397715

The right architecture to enforce this is: have each layer of the UI
maintain its own state machine between mouse_press and mouse_release
events. And only check the state machine in the next level down rather
than lower layers or the bottommost layer of raw LÖVE.
2023-12-01 21:56:35 -08:00
Kartik K. Agaram 007b965b11 audit all asserts
Each one should provide a message that will show up within LÖVE. Stop
relying on nearby prints to the terminal.

I also found some unnecessary ones.

There is some potential here for performance regressions: the format()
calls will trigger whether or not the assertion fails, and cause
allocations. So far Lua's GC seems good enough to manage the load even
with Moby Dick, even in some situations that caused issues in the past
like undo.
2023-11-18 11:32:01 -08:00
Kartik K. Agaram 9656e13774 bugfix: inscript's bug
To fix this I have to first stop incrementally updating screen_bottom1
in the middle of a frame. Now it always has a good value from the end of
a frame.

I'm also running into some limitations in the test I'd ideally like to
write (that are documented in a comment), but I still get some sort of
automated test for this bugfix.
2023-06-04 12:20:24 -07:00
Kartik K. Agaram 3114176ebd change how we handle clicks above top margin 2023-06-03 10:36:05 -07:00
Kartik K. Agaram cdef37c419 get rid of recent_mouse
It's a hack:
  - if you start selecting from below final line the start of the
    selection is the most recent click even if it was forever ago
  - (the crash we're currently fixing) if you start up and immediately
    select all then click below final line => crash. recent_mouse was
    never set.
  - getting rid of it breaks no tests (except the crash we're currently
    fixing)
2023-06-01 22:12:12 -07:00
Kartik K. Agaram 9b3fa33f5b idea: set recent_mouse on mouse events
This helps, but doesn't address the C-a case. As it stands, literally my
first click of the mouse might need access to recent_mouse.line/pos
2023-06-01 21:58:28 -07:00
Kartik K. Agaram 3e848efb08 ah, I see the problem
Text.mouse_pos can sometimes set recent_mouse.time but not
recent_mouse.x/y. I'd assumed x/y is never nil in those situations, but
that's violated. It's most easily seen when typing C-a and then
clicking.
2023-06-01 12:37:17 -07:00
Kartik K. Agaram f1886391c5 some temporary logging to catch a bug
The bug has been spotted twice:

1. In snap.love, I selected text in one node, then another, and hit:
  Error: text.lua:789: attempt to compare nil with number
  stack traceback:
    text.lua:789: in function 'lt1'
    select.lua:19: in function 'clip_selection'
    text.lua:32: in function 'draw'
    edit.lua:117: in function 'draw'
    [string "REPL"]:21: in function 'draw'
    main.lua:152: in function 'draw'
    app.lua:102: in function <app.lua:84>
    [C]: in function 'xpcall'
    app.lua:112: in function <app.lua:111>
    [C]: in function 'xpcall'

  Couldn't reproduce.

2. In text.love, inscript selected all text in a small buffer and then
   clicked outside the text. And got:

  Error: text.lua:784: attempt to compare nil with number
  Traceback
    [love "callbacks.lua"]:228: in function 'handler'
    text.lua:784: in function 'lt1'
    select.lua:19: in function 'clip_selection'
    text.lua:27: in function 'draw'
    edit.lua:117: in function 'draw'
    run.lua:136: in function 'draw'
    main.lua:148: in function 'draw'
    app.lua:42: in function <app.lua:22>
    [C]: in function 'xpcall'

  This is reproducible, and also across forks.
2023-06-01 12:30:19 -07:00
Kartik K. Agaram 876d6298b4 App.width can no longer take a Text
In the process I discovered the horrible fact that Text.x allocates a new Text.
And it gets called (just once, thank goodness) on every single frame.
2023-04-01 18:12:29 -07:00
Kartik K. Agaram 1d3c9f4708 generalize a function 2022-08-18 10:32:03 -07:00
Kartik K. Agaram 2381f7b43f simpler location comparison 2022-08-17 21:23:24 -07:00
Kartik K. Agaram 1d710912cc swap return values 2022-08-17 09:10:52 -07:00
Kartik K. Agaram d61b5dfdeb use line cache for drawings as well 2022-07-20 16:34:09 -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 2859063d9d switch to line index in a function
- Text.to_pos_on_line
2022-07-17 09:19:53 -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 2ae9cacd97 deduce left/right from state where possible 2022-07-12 20:59:24 -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 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 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 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 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 048b6d9d3a drop an arg from a function 2022-07-08 09:44:49 -07:00
Kartik K. Agaram 44fb3ecd55 bugfix: deleting a selection spanning pages 2022-06-26 16:34:06 -07:00
Kartik K. Agaram 009c7abb60 extract a function 2022-06-23 11:09:49 -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
Kartik K. Agaram c1d8201d44 mouse buttons are integers, not strings
Not sure where that idiom comes from or why strings work in some places
(auto-coercion?). I picked it up off some example apps. But
https://love2d.org/wiki/love.mouse.isDown says it should be an integer.
2022-06-14 09:05:02 -07:00
Kartik K. Agaram 059efba79d override mouse state lookups in tests
If I'd had this stuff in my test harness earlier, two recent commits
would have failed tests and given me early warning:
  ff88238ff1
  ff88a2a927
2022-06-12 09:04:21 -07:00
Kartik K. Agaram e4e12c77ad fix a second BSOD in #4 :/
I need more tests.
2022-06-12 07:20:14 -07:00
Kartik K. Agaram 4476eb8946 bugfix: cut (C-x) without first selecting anything 2022-06-09 18:27:09 -07:00
Kartik K. Agaram 4ad51d648b move 2022-06-09 07:29:38 -07:00
Kartik K. Agaram e77157d316 speeding up copy, attempt 1
Problem: repeatedly copying (relatively large) sections of text quickly
makes the app sluggish until it has to be killed. (Thanks John Blommers
for the report.)

When I instrument with prints, the sluggishness seems to happen in
random draw() calls many times after I perform the copy.

I don't know for sure, but I'm initially checking if the cause is
garbage generated by repeated string concatenation.

This attempt doesn't seem to make any difference.
2022-06-09 07:24:40 -07:00
Kartik K. Agaram e2696fcc72 more precise search highlighting 2022-06-03 14:37:32 -07:00
Kartik K. Agaram 1bdb931575 extract a function 2022-06-03 14:30:51 -07:00
Kartik K. Agaram 0d52962b3e extract a couple of files 2022-06-03 14:17:41 -07:00