Commit Graph

58 Commits

Author SHA1 Message Date
Kartik K. Agaram a6f69931f3 Merge template-live-editor-mobile 2024-01-15 02:52:26 -08:00
Kartik K. Agaram 348852ee2b Merge lines.love 2024-01-15 01:38:38 -08:00
Kartik K. Agaram 95d88a8298 use editor state font for width calculations 2024-01-12 05:23:06 -08:00
Kartik K. Agaram 61336b491b Merge lines.love 2023-12-01 22:03:36 -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 9b62cf0afc no selection if State didn't receive mouse_press
This change needs to get backported to all the other forks. We want to
retain the ability to draw other UI elements in our apps, and that means
we can't always assume that a mouse press and mouse release will happen
together. Instead, each layer should manage its own state machine, and
only check for events from the immediately lower layer.

This idea generalizes commit c3cdbb52a.
2023-12-01 20:46:45 -08:00
Kartik K. Agaram 9b18e35aaa bring back syntax highlighting (but so ugly) 2023-11-21 08:53:19 -08:00
Kartik K. Agaram 9d5ca87168 Merge template-live-editor-mobile 2023-11-18 12:59:35 -08:00
Kartik K. Agaram de66b015bc Merge lines.love 2023-11-18 12:21:30 -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 3717d7868a start sketching out a scrollbar
Not quite ideal: the scrollbar computation only considers
screen_bottom1.line and not screen_bottom1.pos, and so it always assumes
the final line is at the bottom of the screen.

I'm making a deeper change here that I might come to regret. I want to
avoid creating new book-keeping for editor mutations, so I'm putting the
work of computing scrollbar data into clear_screen_line_cache. But that
implies the editor should never clear before updating data, and I caught
one place that wasn't true before. A better name helps avoid this in
future. Let's see how much toil this causes in resolving conflicts.
2023-11-18 04:25:31 -08:00
Kartik K. Agaram bf2c2555d6 Merge lines.love 2023-06-04 15:11:24 -07: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 3547c18db6 Merge lines.love 2023-04-02 09:22:32 -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 61b59f4dd6 Merge lines.love 2022-08-18 13:11:41 -07:00
Kartik K. Agaram 1d3c9f4708 generalize a function 2022-08-18 10:32:03 -07:00
Kartik K. Agaram 6d3c059964 Merge lines.love 2022-08-17 21:25:44 -07:00
Kartik K. Agaram 2381f7b43f simpler location comparison 2022-08-17 21:23:24 -07:00
Kartik K. Agaram f11c3f2a9b Merge lines.love 2022-08-17 09:17:00 -07:00
Kartik K. Agaram 1d710912cc swap return values 2022-08-17 09:10:52 -07:00
Kartik K. Agaram a655c2113c bring back a level of wrapping
Many projects will require the ability to add metadata to lines, so
let's not drop that.
2022-08-15 11:00:35 -07:00
Kartik K. Agaram 9d792a203b new fork: rip out drawing support 2022-08-14 09:20:14 -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