saikyun / freja

Self-modifiable editor for coding graphical things
68 stars 3 forks source link

gb/column! seems to report incorrect value sometimes #60

Closed sogaiu closed 2 years ago

sogaiu commented 2 years ago

With freja at commit: 700137587b450ae504c5f981a991be9e3fc3ee30 and the following as the editor buffer content:

(import freja/new_gap_buffer :as gb)
(import freja/state)
(import freja/default-hotkeys :as dh)

(defn current-gb
  []
  (get-in state/editor-state [:stack 0 1 :editor :gb]))

and the cursor at the end of the first line, evaluating:

(gb/column! (current-gb) ((current-gb) :caret))

via eval-expr-dialog (default hotkey ctrl-shift-e), yields 0 here.

The value I expected was non-zero, or the column number corresponding to the last cursor position(?) of the first line. I think that should be 36 in this case.

With the cursor at the end of some other lines (e.g. the second or third line) I get values that appear to make sense. 20 for the second line and 37 for the third line.

sogaiu commented 2 years ago

This is a guess, but may be this occurs because column! indirectly relies on a peg which might require that there is an end of line indicator: https://github.com/saikyun/freja/blob/700137587b450ae504c5f981a991be9e3fc3ee30/freja/new_gap_buffer.janet#L1268

The case that reproduces above is the first line and the position of the cursor is before all newlines in the buffer.

sogaiu commented 2 years ago

Perhaps if peg/match fails here: https://github.com/saikyun/freja/blob/700137587b450ae504c5f981a991be9e3fc3ee30/freja/new_gap_buffer.janet#L1277 a little bit more processing could happen here: https://github.com/saikyun/freja/blob/700137587b450ae504c5f981a991be9e3fc3ee30/freja/new_gap_buffer.janet#L1279 before settling on a final number.

saikyun commented 2 years ago

Should be fixed with a1661157eca47c2bdae3ba199a83a15ac1c856c1 Please try it :)

sogaiu commented 2 years ago

Seems to be working better :)

TYVM!

saikyun commented 2 years ago

Nice :D

Den tis 15 feb. 2022 14:02sogaiu @.***> skrev:

Closed #60 https://github.com/saikyun/freja/issues/60.

— Reply to this email directly, view it on GitHub https://github.com/saikyun/freja/issues/60#event-6074759160, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAS46Z6BXHMGIJ25VIMUULDU3JFF7ANCNFSM5M57GXLQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>