Skip to content

Commit

Permalink
Fix recording of unicode characters in record (#64)
Browse files Browse the repository at this point in the history
Fixes #63. (as in, I no longer see the error)

The fix is to replace

```julia
    i = min(length(rec.text), rec.cursor_index)
    a = rec.text[begin:i]
    b = rec.text[i+1:end]
```
with
```julia
    i = min(length(rec.text), rec.cursor_index)
    a = ""
    b = ""
    if i > 0
        a = rec.text[begin:nextind(rec.text, i-1)]
        b = rec.text[nextind(rec.text, i):end]
    end
```
which accounts for strings which are not uniformly indexed, like "aαbβcγ" which has its indices at `1, 2, 4, 5, 7, 8`.
  • Loading branch information
MilesCranmer authored and caleb-allen committed Jul 14, 2023
1 parent 3477c41 commit 4c623b3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/changes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ Base.:(==)(x::BufferRecord, y::BufferRecord) =

function Base.show(io::IO, rec::BufferRecord)
i = min(length(rec.text), rec.cursor_index)
a = rec.text[begin:i]
b = rec.text[i+1:end]
a = ""
b = ""
if i > 0
a = rec.text[begin:nextind(rec.text, i-1)]
b = rec.text[nextind(rec.text, i):end]
end
print(io, "BufferRecord(\"" * a * "|" * b * "\"), $(rec.cursor_index))")
end

Expand Down

0 comments on commit 4c623b3

Please sign in to comment.