Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: scripting methods for cusor operation #2533

Closed
davuses opened this issue May 19, 2022 · 8 comments
Closed

Feature request: scripting methods for cusor operation #2533

davuses opened this issue May 19, 2022 · 8 comments
Labels
Scripting Stale No activity for a while Type: Support

Comments

@davuses
Copy link

davuses commented May 19, 2022

I've always wanted to write a script to regester custom actions for cursor movement. In the scripting document, I found two methods QOwnNotes provides with regards to cursor position or movement: noteTextEditSetCursorPosition(int position) and noteTextEditCursorPosition().

With these two methods, I can move cursor forward or backward by 1 (or a certain number) character like this:
script.noteTextEditSetCursorPosition(currentPosition + 1);

But I couldn't figure out how to move cursor to next line or previous line, just as the simple up arrow and down arrow keys do, probably an extra API for getting current line number is necessary. Or even more, how to move cursor to next/previous word or block.

I know the cursor moving keymap is available in Vim mode, but I'd like to just have some shortcuts for cursor moving without having to switch to full Vim mode.

I there a way to implement these cursor moving actions just with the API currently provided by QOwnNotes that I missed out? If so, could you give me some advises how to do that? If not, it would be very nice to have some extra scripting methods for cursor movement in QOwnNotes, I think this will offer a lot of flexibility for custom cursor operation.

Thank you in advance for your help:)

@pbek
Copy link
Owner

pbek commented May 19, 2022

Since you have access to the note text you could calculate pretty any position by counting how many characters each line has, can't you?

@pbek pbek added the Scripting label May 19, 2022
@davuses
Copy link
Author

davuses commented May 19, 2022

Since you have access to the note text you could calculate pretty any position by counting how many characters each line has, can't you?

@pbek
I don't think I can do the character counting of each line with two methods above, any sugestions what methods can do the job?

Just find two methods that are probably related, I can select current line with noteTextEditSelectCurrentLine and get the start position and end position with noteTextEditSelectionStart()· and noteTextEditSelectionEnd()`. But how about other lines?

@pbek
Copy link
Owner

pbek commented May 19, 2022

let lineList = noteText.split("\n");

// First line
lineList[0];

// Second line
lineList[1];

@pbek
Copy link
Owner

pbek commented May 19, 2022

And then you could count the characters in each line...

@davuses
Copy link
Author

davuses commented May 19, 2022

let lineList = noteText.split("\n");

// First line
lineList[0];

// Second line
lineList[1];

@pbek Thank you, I did manage to achieve that. Is there a way to move cursor to next/previous word or block?

@pbek
Copy link
Owner

pbek commented May 19, 2022

You could try to split the lines by word boundary \b with noteLine.split("\b"); and count how many words in a line your cursor currently is.

@github-actions
Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the Stale No activity for a while label Jun 19, 2022
@github-actions
Copy link

github-actions bot commented Jul 4, 2022

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions bot closed this as completed Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scripting Stale No activity for a while Type: Support
Projects
None yet
Development

No branches or pull requests

2 participants