micro-editor / micro-editor/micro

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

Open
#3,628 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
29.6k
Forks
1.4k
Avg merge
2d 18h
Merged PRs (30d)
10

Description

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:

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in internal/buffer/eventhandler.go around ExecuteTextEvent and the linked TextEventReplace handling at lines 125–135. Compare its newline behavior with the LineArray remove and insert functions, then verify that multiline changes produce the correct start and end positions for the LSP.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.