Commit Graph

972 Commits

Author SHA1 Message Date
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 ea4a8379fe rfind bugfix: handle empty pattern like string.find 2023-10-15 14:21:41 -07:00
Kartik K. Agaram 6b723363b8 add some tests for rfind 2023-10-15 14:20:55 -07:00
Kartik K. Agaram 69d86cae5b fix all tests in LÖVE v12
This is all quite hacky. Many of my tests are unfortunately brittle to
changes in text rendering. Fortunately there's only one test that
currently requires a hacky special case (and a second test I tweaked
slightly to be more robust).

I can't think of a better approach. It doesn't help to standardize the
font, because version changes still come with changes to text-shaping
algorithms even if the font itself is unchanged. I could base all my
assertions on the widths of individual characters, but that would make
the tests much less readable and not express intent as clearly. So here
we are, with hopefully just a few hacky special cases (there might be a
few more as LÖVE v12 advances towards publication, and in further
versions).
2023-10-09 20:25:08 -07:00
Kartik K. Agaram 6e391d7875 start supporting LÖVE v12
To do this I need some support for multiple versions. And I need an
'error' mode to go with existing 'run' and 'source' modes
(`Current_app`). Most errors will automatically transition to 'source'
editor mode, but some errors aren't really actionable in the editor. For
those we'll use 'error' mode.

The app doesn't yet work with LÖVE v12. There are some unit tests failing
because of differences in font rendering.
2023-10-09 20:05:19 -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 c43d884b6f indent 2023-09-16 22:41:55 -07:00
Kartik K. Agaram 9241fedf3a port an old fix to source editor 2023-09-16 22:40:46 -07:00
Kartik K. Agaram 6e2137c5b6 bugfix to the helper I added yesterday 2023-09-16 22:39:51 -07:00
Kartik K. Agaram 715c6fd32f source: show file being edited in window title bar 2023-09-15 13:36:27 -07:00
Kartik K. Agaram 6ed60848a4 delete some dead code
This is a holdover from the days of bifold text.
2023-09-15 13:33:26 -07:00
Kartik K. Agaram 76f119b7b9 hide line numbers from log browser 2023-09-15 13:30:42 -07:00
Kartik K. Agaram ab5ba3f3e5 assume starty can be nil in update
This is a backport of a bugfix in pensieve.love. It's not _technically_
a bug here in lines.love, but it seems worth establishing an
architectural invariant (or rather lack of invariant).

LÖVE's standard event loop performs the following sequence of operations
in a single frame:
  * process events
  * update
  * draw

Ideally any mutations to global state happen during the first two
phases, while drawing includes no mutation.

However, there is a special case: `starty`, the top y coordinate for
each each line in the editor. This is used all over the place, and the
cheapest way to compute it is to simply save it while drawing.

However, draw by definition only updates `starty` for lines that are
drawn on screen. To avoid stale data on lines off screen, say after
scrolling, events often clear `starty` for all lines, leaving it to the
next draw phase to repopulate the right lines.

Sandwiched between the above two "however"s, the update phase needs to
gracefully handle `starty` being nil in the occasional frame right after
an event.

I think I've audited all our uses of `starty`, and this commit fixes the
only place that violates this rule.
2023-09-15 11:13:04 -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 0e20565e17 clean up a slight jitter when drawing circles
Earlier the ghost while drawing wouldn't quite match the final shape.
Now the math is identical in draw_pending_shape.

It's a little unfortunate that we have this duplication of formulae.

At least there are no other stray calls of App.mouse_x in
draw_pending_shape.
2023-09-15 08:30:15 -07:00
Kartik K. Agaram 1fd30c0462 always show line numbers in source editor
The drawing buttons are now absolutely positioned, which is a horrible
hack. But for just the source editor it seems good enough. The
alternative is to modify magic constants in all the tests :/
2023-09-14 22:27:38 -07:00
Kartik K. Agaram 7062963888 Revert "deemphasize the source editor"
Now that we have decent error handling, I think we can encourage people
to press ctrl+e again.

This reverts commit 4b43e9e85d.
2023-09-10 21:45:59 -07:00
Kartik K. Agaram 790b7f18db yet another bugfix X-(
This time it really does work with pensieve.love
2023-09-09 09:27:56 -07:00
Kartik K. Agaram 0016d668bc two bugfixes
Annoying dangers of testing in one fork and committing upstream
(where it isn't used yet).
2023-09-09 09:09:14 -07:00
Kartik K. Agaram bcd7f6b598 new primitives for reading/writing files
These are like versions in nativefs, but only support absolute paths.
I want to be thoughtful about the precise location at each call-site.

It's a little ugly that app.lua now has a dependency on file.lua. Or
source_file.lua for the source editor.
2023-09-09 08:56:21 -07:00
Kartik K. Agaram 31266e23f5 reorder 2023-09-09 08:27:27 -07:00
Kartik K. Agaram 87ea2af2da a few more testable file-system operations 2023-09-08 14:03:40 -07:00
Kartik K. Agaram e74b92b733 show any error after switching to source editor
Error_message is a special global. It's set when the app (Current_app = 'run')
encounters an error and switches to the source editor, and cleared when
switching from source editor back to the app.
2023-09-04 15:07:54 -07:00
Kartik K. Agaram adfe94b9fc switch to source editor on error
If we're already in source editor we'll quit as before.

It's ugly that app.lua now knows about run.lua. But it's a start.
2023-09-04 13:07:53 -07:00
Kartik K. Agaram 99495355b4 stop using keyboard.isDown
It doesn't work on Android, and it's not much work to avoid.
2023-09-04 00:22:31 -07:00
Kartik K. Agaram 6e54ad55d9 yet another set of bugfixes
The key API change I'd underestimated: opening a file used to return nil
on failure, and now returns false.
2023-08-30 23:52:25 -07:00
Kartik K. Agaram 06ad5c4e8c bugfix in source editor
We now need to explicitly select the directory we want to read from.
2023-08-30 22:30:20 -07:00
Kartik K. Agaram f82c0de502 cleaner API for file-system access
Thanks to physfs and nativefs.lua

nativefs still introduces some inconsistencies with love.filesystem with
relative paths:

  * love.fs.read: reads from save dir if it exists, falls back to source dir if not
  * nativefs.read: reads from save dir if it exists, falls back to source dir if not ✓

  * love.fs.write: always writes to save dir
  * nativefs.write: always writes to source dir (since no restrictions)

  * love.fs.newFile followed by file:open('r'): reads from save dir if it exists, source dir if not
  * nativefs.newFile followed by file:open('r'): always reads from working dir

  * love.fs.newFile followed by file:open('w'): always writes to save dir
  * nativefs.newFile followed by file:open('w'): always writes to working dir

So avoid using relative paths with App primitives.
2023-08-30 19:04:06 -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 ca4ad8a9e5 reorganize app.lua and its comments
I was so sure my comments were clear when I wrote this a year ago. They
were shit. So, most probably, is the current iteration. Feedback
appreciated.
2023-08-26 15:15:42 -07:00
Kartik K. Agaram 9c38e505a5 correct various names in this and other pre-freewheeling forks 2023-08-26 13:15:32 -07:00
Kartik K. Agaram d76541dec3 fix method name in documentation 2023-08-26 13:04:39 -07:00
Kartik K. Agaram 8603ca5d39 tweak wording in test list 2023-08-07 06:52:25 -07:00
Kartik K. Agaram b93c0cd6cc reorganize some comments
This keeps things consistent with other forks (links, lines-and-links)
that are "conceptually upstream" of the source editor.
2023-07-31 09:27:31 -07:00
Kartik K. Agaram bb3e12eb5f bugfix: search highlight straddling screen lines 2023-07-31 09:15:48 -07:00
Kartik K. Agaram 2b52383e18 remove a duplicate print to screen
In addition to being more efficient, this will simplify the next bugfix.
2023-07-31 08:56:20 -07:00
Kartik K. Agaram 8879fd6f29 extract a variable 2023-07-31 08:49:24 -07:00
Kartik K. Agaram d6c06db97a bugfix: highlight search patterns on the right line
scenario:
* position a wrapped line on screen
* search for the word immediately after the point of wrapping

Before this commit the word would be highlighted twice:
  - at the end of the first screen line
  - at the start of the second screen line

Now it shows up at the right place.
2023-07-31 08:40:22 -07:00
Kartik K. Agaram f7f42b0bef hoist and duplicate a conditional
I'm duplicating the bounds check when drawing cursor and search
highlight because they're separate concerns and require subtly different
logic.
2023-07-31 08:40:07 -07:00
Kartik K. Agaram 484b76f5c6 improve a comment 2023-07-31 08:21:38 -07:00
Kartik K. Agaram 52ba030eaa drop an unused arg 2023-07-11 08:36:42 -07:00
Kartik K. Agaram bca7f82598 standardize between run and source some more
We shouldn't be thinking about saving settings when we're initializing
window geometry.
2023-07-10 17:16:58 -07:00
Kartik K. Agaram 7f4c5f847b simplify saving settings
We don't ever call one app's settings while Current_app is the other.
2023-07-10 17:14:38 -07:00
Kartik K. Agaram a8747478ff bugfix: Windows pushing title bar off screen
I'm learning the hard way that resizing the window is a big deal. Only
do this when someone explicitly requests it, otherwise follow LÖVE's
defaults.

Therefore we're also going to stop trying to be smart when showing the
log browser. Leave window resizing to manual operations.

Now initialization looks a lot more similar for the run and source apps.
2023-07-10 17:09:09 -07:00
Kartik K. Agaram 3f52063d02 delete flags that have never been exercised
Initialization is getting complex, and I'm finding bugs.
2023-07-10 16:33:17 -07:00
Kartik K. Agaram b42f08cb79 bugfix: preserve window position
I just noticed we hadn't got this bugfix for Linux on the main app. How
had we not noticed this issue before? Answer: lines.love windows tend to
be tall and skinny, and resize must keep the window entirely within the
screen. So the window was staying in place just because it happened to
be running up against the bottom.
2023-07-10 16:08:18 -07:00
Kartik K. Agaram e68261d7a3 bugfix: preserve window position 2023-07-10 15:50:47 -07:00
Kartik K. Agaram 9df1c3f997 support for num pad
It'll only work after LÖVE v12 comes out.
2023-07-07 18:40:12 -07:00
Kartik K. Agaram 33934337ab experiment: convert to Pijul
https://pijul.org
2023-06-25 06:12:36 -07:00