Commit Graph

213 Commits

Author SHA1 Message Date
Kartik K. Agaram 837e3bef1b Merge lines.love 2024-02-16 21:26:18 -08:00
Kartik K. Agaram 219ee11686 ensure tapping on editor brings up soft keyboard 2024-02-16 21:16:29 -08:00
Kartik K. Agaram 4f0561b233 Merge lines.love 2024-02-04 17:30:47 -08:00
Kartik K. Agaram 83722db5e4 bugfix: don't clear selection on M-arrow
We now treat all arrow chords as cursor movement.

Many thanks to Ryan Kessler (https://tone.support) for reporting this
issue.
2024-02-04 09:31:36 -08:00
Kartik K. Agaram 1d1a829d5b more carefully pass the 'key' arg around 2024-02-04 09:30:48 -08:00
Kartik K. Agaram 334ec7bf7c Merge lines.love 2023-12-29 14:24:04 -08:00
Kartik K. Agaram bd2179d8aa bugfix
scenario: run without config file, quit, run again
expected: font size remains the same on second run

Before this commit it was increasing on each run.
It turns out the font height that you pass into love.graphics.newFont()
is not the result of font:getHeight().
2023-12-29 11:52:28 -08:00
Kartik K. Agaram 0f4aea6db7 pull font into editor
Now it adjusts the current font for itself.
And it's up to the caller to adjust the current font after.
2023-12-29 11:18:41 -08:00
Kartik K. Agaram 3fb3581afb Merge lines.love 2023-12-16 23:47:55 -08:00
Kartik K. Agaram c29be0ffce streamline button.lua 2023-12-16 23:41:10 -08:00
Kartik K. Agaram d22da0802d Merge lines.love 2023-12-03 11:21:25 -08:00
Kartik K. Agaram 0d3db19c85 clearing starty is redundant in mutations
We'll end up calling Text.redraw_all anyway, which will clear starty and
much more besides.

We'll still conservatively continue clearing starty in a few places
where there's a possibility that Text.redraw_all may not be called. This
change is riskier than most.
2023-12-03 10:32:05 -08:00
Kartik K. Agaram 1ee2ced88a Merge lines.love 2023-12-01 22:02:23 -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 aa592d25c4 Merge lines.love 2023-11-18 12:17:17 -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 e682fa1b7a Merge lines.love 2023-10-16 23:22:03 -07:00
Kartik K. Agaram 4b3f359526 clearer API for drawing a button
Make it more obvious that the color passed in is just for the background.
The icon will do the rest.
r/g/b keys are more consistent with App.color().
2023-10-16 22:57:46 -07:00
Kartik K. Agaram a19712894c bugfix
Scenario:
  * select a line or two
  * delete
  * press C-z to undo. The lines return and are highlighted.
  * press C-y to redo.

Before this commit the editor was crashing:

  Error
    edit.lua:169: assertion failed!
  Traceback
    [love "callbacks.lua"]:228: in function 'handler'
    [C]: in function 'assert'
    edit.lua:169: in function 'draw'
    text.lua:1064: in function 'cursor_out_of_screen'
    edit.lua:487: in function 'keychord_press'
    run.lua:842: in function 'keychord_press'
    main.lua:215: in function 'keychord_press'
    keychord.lua:11: in function <keychord.lua:5>
    app.lua:31: in function <app.lua:22>
    [C]: in function 'xpcall'

I was forgetting a step in C-y that was done in C-z. Now undo and redo
are symmetric.
2023-10-15 23:23:20 -07:00
Kartik K. Agaram 9b4caadf3f Merge lines.love 2023-09-20 14:21:55 -07:00
Kartik K. Agaram bd6f7d48e7 bugfix: clear selection when clicking above or below lines
Matt Wynne pointed out that snap.love would crash when a node went off
screen. While debugging it I noticed that selection1 was being set when
it shouldn't be.

Turns out I introduced a bug when I fixed the inscript bug back in June
(commit 9656e13774). One invariant I want to preserve is: selection1
should be unset after a mouse click (press and release without
intervening drag). This invariant was violated in my bugfix back in
June. I was concerned only with selection back then, and I didn't
realize I was breaking the mouse click case (in a fairly subtle way; you
can have selection set, and when it's set identically to the cursor
everything looks the same).

I think there might still be an issue in snap.love after this fix. I
noticed screen_bottom1.pos was nil, and as far as I recall that should
never happen.
2023-09-20 13:39:29 -07:00
Kartik K. Agaram 1b6d04f678 Merge lines.love 2023-09-17 09:21:50 -07:00
Kartik K. Agaram c43d884b6f indent 2023-09-16 22:41:55 -07:00
Kartik K. Agaram 6e2137c5b6 bugfix to the helper I added yesterday 2023-09-16 22:39:51 -07:00
Kartik K. Agaram f935070ba7 Merge lines.love 2023-09-15 23:51:12 -07:00
Kartik K. Agaram bafc45b028 bugfix: crash when using mouse wheel
All the Text functions assume the cursor is always on a text line. I was
violating that invariant.

* When scrolling up, I start the cursor at the top-most line below the
  screen top.

* When scrolling down, I start the cursor at the top-most line below the
  screen bottom.

  I think it would feel slightly more natural for it to be the
  bottom-most line above the screen bottom.

  However, the Text functions maintain an invariant that the bottom-most
  line in a buffer will be text. There's no such invariant for the
  top-most line.
2023-09-15 08:52:39 -07:00
Kartik K. Agaram 0a12e4c733 change a helper slightly 2023-09-15 08:46:36 -07:00
Kartik K. Agaram b826451091 Merge lines.love 2023-08-30 22:22:31 -07:00
Kartik K. Agaram 7e97a2a1e7 make a few names consistent with snake_case 2023-08-30 06:44:54 -07:00
Kartik K. Agaram b7f2727b0e bugfix: screen_bottom1 might never be written
See previous commit.
2023-06-10 17:42:45 -07:00
Kartik K. Agaram 5ba9aa9e57 new bug: screen_bottom1 might never be written
Scenario: press C-f and search for something.
Some of the time we get a crash with this call stack:

  Error
  text.lua:970: attempt to compare nil with number

  Traceback
  [love "callbacks.lua"]:228: in function 'handler'
  text.lua:970: in function 'lt1'
  search.lua:72: in function 'search_next'
  run.lua:985: in function 'search_next_in_pane'
  run.lua:939: in function 'search_next'
  run.lua:784: in function 'text_input'
  main.lua:237: in function <main.lua:230>
  app.lua:31: in function <app.lua:22>
  [C]: in function 'xpcall'

Not fixed yet.

The cause: plan_draw is conservative and sometimes tries to render panes
that never overlap the viewport.

This bug was exacerbated by fixing the inscript bug which started
setting screen_bottom1 to nil. But the problem existed before as well,
we just operated on stale screen_bottom1 locations.

This bug doesn't generalize to many other scenarios. It isn't a problem
for forks without the surface metaphor, though it might affect
driver.love as well. Even in pensieve.love, the only place that uses
screen_bottom while spanning multiple editors is find across the entire
surface.
2023-06-10 17:34:48 -07:00
Kartik K. Agaram d20a7cd8a2 Merge lines.love 2023-06-08 01:10:43 -07:00
Kartik K. Agaram 14c08f9bd9 several bugfixes in saving/loading cursor position 2023-06-08 01:02:54 -07:00
Kartik K. Agaram 066d7fae12 Merge lines.love 2023-06-06 13:06:26 -07:00
Kartik K. Agaram 96c056bd4c return height of editor widget after drawing 2023-06-06 12:52:44 -07:00
Kartik K. Agaram e2cb177678 Merge lines.love 2023-06-04 12:40:22 -07:00
Kartik K. Agaram 637e28f300 port inscript's bugfix to source editor 2023-06-04 12:33:23 -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 cf0ba7c154 handle wrapping lines 2023-06-03 10:44:11 -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 4604115a43 bugfix
loc.pos should never be computed based on #line.data

scenario:
  - open a surface containing some unicode
  - search for a rare pattern that requires scanning over entire surface
    including the unicode
2023-05-22 00:09:47 -07:00
Kartik K. Agaram d0792ba1b4 Merge lines.love 2023-04-08 22:00:35 -07:00
Kartik K. Agaram c969fcdd85 enhance bugfix of commit a9aa3436f (Dec 2024)
Scenario:
* start out with some text on screen
* select some text A, delete
* select some more text B, delete
* press C-z twice to restore A and B
* press C-y twice

Before this commit only the first C-y was having an effect (deleting B).
The second was failing to delete A.
2023-04-08 21:55:51 -07:00
Kartik K. Agaram 19ad066cba Merge lines.love 2023-04-03 09:21:39 -07:00
Kartik K. Agaram 282983d084 switch source side to new screen-line-based render
Also copy over the implementation of links from pensieve.love.
2023-04-03 08:33:07 -07:00
Kartik K. Agaram a3e9963ba1 Merge lines.love
Bring back the 2 pending tests.
2023-04-02 17:25:58 -07:00