micro icon indicating copy to clipboard operation
micro copied to clipboard

[Feature Request]: Allow multiline text in `TextEventReplace`

Open usfbih8u opened this issue 11 months ago • 1 comments

I am contributing to the Micro Language Server Protocol (mlsp) and have encountered an issue with the ExecuteTextEvent() method when handling TextEventReplace events. Currently, when deltas are created, it assumes that there are no newline characters within the text.

Is this an edge case that has not been considered, a bug, or an intended feature?

Please refer to line 130, where the same Y value is used for both Start and End:

https://github.com/zyedidia/micro/blob/f5debdf8fe94ebf55ab95824c678938ce439926e/internal/buffer/eventhandler.go#L125-L135

You can find more details about the issue in these messages:

  • https://github.com/Andriamanitra/mlsp/pull/23#discussion_r1912292428
  • https://github.com/Andriamanitra/mlsp/pull/23#issuecomment-2590975293

We need to send the same changes to the LSP that Micro does. A possible solution on our side (similar to what needs to be done in Micro) could be the following:

-- treat as pseudocode
local splits = strings.Split(delta.Text)
local nsplits = #splits
local last_split_len = util.CharacterCountInString(splits[nsplits])
local char_begin = nsplits == 1 and delta.Start.X or 0
range["start"]  = ...
range["end"] = {
    line = delta.Start.Y + nsplits - 1,
    character = char_begin + last_split_len
}

The LineArray functions remove and insert appear to handle newlines (likely for deleting multiline selections), but the upstream ExecuteTextEvent does not.

usfbih8u avatar Jan 23 '25 03:01 usfbih8u

Looks like a bug.

JoeKar avatar Jan 23 '25 19:01 JoeKar