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

Scripting function request: select #1167

Closed
sanderboom opened this Issue Mar 17, 2019 · 22 comments

Comments

Projects
None yet
2 participants
@sanderboom
Copy link
Contributor

sanderboom commented Mar 17, 2019

As discussed, o.a. for qownnotes/scripts#57 it would be nice to have functionality exposed to scripting that enables to:

  • select parts of the note (especially the current line)
  • receive the selection
  • create (or reapply) a selection

Goal in the toggle-checkbox script:

  • single checkbox/line:
    • user has cursor on a line in a note
    • presses shortcut
    • current line is selected
    • content available to script
    • scripts toggles checkbox
    • note content is updated
  • multiple lines:
    • user selected lines
    • presses shortcut
    • content available to script
    • script toggles checkboxes
    • note content is updated
    • content keeps selection / selection is reapplied

Hope this is clear, thanks in advance!

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 18, 2019

You will get this in the next release

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 18, 2019

Don't forget to bump the minimum version in your script 😉

@pbek pbek added this to the 19.3.2 milestone Mar 18, 2019

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 18, 2019

19.3.2

  • there now is a new script settings variable for select-boxes
    • you can define items with an index and a text
    • you will receive the selected index
    • for more information please take a look at the scripting documentation

pbek added a commit that referenced this issue Mar 18, 2019

@sanderboom

This comment has been minimized.

Copy link
Contributor Author

sanderboom commented Mar 18, 2019

You will get this in the next release

'this' === dropdown in settings?
Awesome! 🙌

This issue is actually about being able to set/get the selected text in a note 😉

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 18, 2019

lol, I totally thought you were talking about the select box feature

@pbek pbek removed the help wanted label Mar 18, 2019

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 18, 2019

@sanderboom what beside current line is selected doesn't work yet?

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 18, 2019

reapply a selection

that will never work if the text in the note text edit was changed

@pbek

This comment has been minimized.

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 18, 2019

19.3.2

  • there now is a new scripting command script.noteTextEditSelectCurrentLine()
    to select the current line in the note text edit

pbek added a commit that referenced this issue Mar 18, 2019

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 18, 2019

There now is a new release, could you please test it and report if it works for you?

@sanderboom

This comment has been minimized.

Copy link
Contributor Author

sanderboom commented Mar 18, 2019

there now is a new scripting command script.noteTextEditSelectCurrentLine() to select the current line in the note text edit

Works grrreat 😃

Implemented the 2 new features right away: qownnotes/scripts#58

reapply a selection

that will never work if the text in the note text edit was changed

Can you pass the start- and end-postiion of the selection? All we need then is a method to apply a selection from start- to end-position... Idea?

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 19, 2019

Can you pass the start- and end-postiion of the selection? All we need then is a method to apply a selection from start- to end-position... Idea?

those are just absolute positions (the Xth character) in the text edit. if you change the text those positions would change too :/

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 19, 2019

@sanderboom

This comment has been minimized.

Copy link
Contributor Author

sanderboom commented Mar 19, 2019

those are just absolute positions (the Xth character) in the text edit. if you change the text those positions would change too :/

I think I can work with that. I know what I change so I should be able to figure out what the new end position for the selection needs to be. The starting position will stay the same. Apply the new selection would be the last thing to do in the customAction.

The goal is to make the multiline-toggle as easy as the single-line: without manual reselecting:
Peek 2019-03-19 10-05

What do you think?

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 19, 2019

So what scripting functionality would you need? An api to read the position of the current selection (e.g. https://doc.qt.io/qt-5/qtextcursor.html#selectionStart) and a method to set a selection (from / to).

@sanderboom

This comment has been minimized.

Copy link
Contributor Author

sanderboom commented Mar 19, 2019

Yes, get the selectionStart, get the selectionEnd and setSelection from/to would be perfect!

@pbek pbek modified the milestones: 19.3.2, 19.3.3 Mar 19, 2019

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 19, 2019

You will get those commands in the next release.

pbek added a commit that referenced this issue Mar 19, 2019

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 19, 2019

19.3.3

  • there now are new scripting commands script.noteTextEditSetSelection(),
    script.noteTextEditSelectionStart() and script.noteTextEditSelectionEnd()
    to set and get the currently selected text in the note text edit
@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 19, 2019

There now is a new release, could you please test it and report if it works for you?

@sanderboom

This comment has been minimized.

Copy link
Contributor Author

sanderboom commented Mar 20, 2019

Strange, yay -Syyu --devel does not present the new version. I am building now from the snapshot download from the AUR directly.

@sanderboom

This comment has been minimized.

Copy link
Contributor Author

sanderboom commented Mar 20, 2019

The new functions work great. Didn't have to use the endPos at all, I just have startPos + new length 😉

Apparently the .length is utf-8 proof 👍

Peek 2019-03-20 08-33

BTW, I do this: var resultText = lines.join('\n');, do I need to take Windoze users into account? How to know whether I should use \r\n instead?

@pbek

This comment has been minimized.

Copy link
Owner

pbek commented Mar 20, 2019

Awesome!

do I need to take Windoze users into account

good question, most of the time I also just take \n into account...

@pbek pbek closed this Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.