Skip to content

add NewCursor binding for lua plugins#2941

Open
mosskjohnson wants to merge 2 commits into
micro-editor:masterfrom
mosskjohnson:new-cursor
Open

add NewCursor binding for lua plugins#2941
mosskjohnson wants to merge 2 commits into
micro-editor:masterfrom
mosskjohnson:new-cursor

Conversation

@mosskjohnson

Copy link
Copy Markdown

This adds a binding to the NewCursor function for use in lua plugins.

Comment thread cmd/micro/initlua.go Outdated
ulua.L.SetField(pkg, "ByteOffset", luar.New(ulua.L, buffer.ByteOffset))
ulua.L.SetField(pkg, "Log", luar.New(ulua.L, buffer.WriteLog))
ulua.L.SetField(pkg, "LogBuf", luar.New(ulua.L, buffer.GetLogBuf))
ulua.L.SetField(pkg, "NewCursor", luar.New(ulua.L, buffer.NewCursor))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to move it above, after NewBufferFromFile, to keep these New* functions grouped together.

Comment thread runtime/help/plugins.md Outdated
- `Log(s string)`: writes a string to the log buffer.
- `LogBuf() *Buffer`: returns the log buffer.

- `NewCursor(b *Buffer, l Loc)`: creates a new cursor struct.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@mosskjohnson

Copy link
Copy Markdown
Author

Just moved it.

@mosskjohnson mosskjohnson requested a review from dmaluka March 27, 2024 00:53
Comment thread cmd/micro/initlua.go
ulua.L.SetField(pkg, "Log", luar.New(ulua.L, buffer.WriteLog))
ulua.L.SetField(pkg, "LogBuf", luar.New(ulua.L, buffer.GetLogBuf))
ulua.L.SetField(pkg, "NewCursor", luar.New(ulua.L, buffer.NewCursor))
ulua.L.SetField(pkg, "LogBuf", luar.New(ulua.L, buffer.GetLogBuf))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add trailing spaces.

@dmaluka

dmaluka commented Mar 30, 2024

Copy link
Copy Markdown
Collaborator

Still, what about my question #2920 (comment)?

I.e. isn't NewCursor() too low-level a detail to be exposed to plugins? Perhaps the needed functionality can be already achieved from Lua with existing BufPane methods like SpawnMultiCursor()? Or if those methods are not quite suitable since they do "too much", perhaps we should just add a new simple method to BufPane or to Buffer, which would, roughly speaking, just do NewCursor() + AddCursor() + MergeCursors() and nothing else?

@Gavin-Holt

Copy link
Copy Markdown

Hi,

I would like to see three changes in multicursor behavior:

  1. Make multiple text selections, each with a cursor:
  • Ctrl+Left+Click+Drag - Region
  • Ctrl+DoubleClick - Word
  • Ctrl+TripleClick - Line
  1. New actions ( see SpawnMultiCursorAll - feature request #2920)
  • SpawnMultiCursorAll - Search with current selection or current word, and select all for editing.
  • SpawnMultiCursorFound - Select/edit all matches for last find, allows literal or regex searches.
    NB. Using the search facility will allow easy highlighting or scrolling to review all the selections before editing.
  1. Merge contiguous cursors on the same line
  • Delete selections before any editing

SciTE does 1+3 for an example of functionality.

Kind Regards Gavin Holt

@dmaluka

dmaluka commented Aug 31, 2024

Copy link
Copy Markdown
Collaborator

With #3441 merged, cursors can now be added via bp:SpawnCursorAtLoc() instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants