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

Code block only adds single pair of ` and no new lines. #912

Closed
maqp opened this Issue May 15, 2018 · 26 comments

Comments

Projects
None yet
2 participants
@maqp

maqp commented May 15, 2018

Expected behaviour

Pressing Ctrl + Shift + C produces

```
<caret here>
```

at this position when the code block

public class main {

    public static void main(String[] args){
        System.out.println("Hello World");
    }
}

is pasted, it is shown nicely by the preview

Actual behaviour

Pressing Ctrl + Shift + C produces

`<caret here>`

when pasting the code block, the created block is not correct

Steps to reproduce

See above

Output from the debug section in the settings dialog

Way too much private info in this. Let me know if the stuff below is not enough

Version: 18.05.2
Build date: May 8 2018
Build number: 439
Platform: linux
Operating System: Ubuntu 17.10
Build architecture: x86_64
Current architecture: x86_64
Release: Launchpad PPA
Qt Version (build): 5.9.1
Qt Version (runtime): 5.9.1
Portable mode: no
Application arguments: QOwnNotes
Qt Debug: 0
Locale (system): en_US

Relevant log output in the Log panel

Not relevant

@pbek pbek added the question label May 15, 2018

@pbek

This comment has been minimized.

Owner

pbek commented May 15, 2018

It depends on what you were selecting. By default only a inline code block is produced, if you are selecting some multi-line text a multi-line code block is produced. In your case you didn't select something, so you only get a inline-code block... Of course you could press the shortcut three times or write a script for inserting three ticks by default.

@pbek pbek closed this May 15, 2018

@maqp

This comment has been minimized.

maqp commented May 15, 2018

I modified the paste-latex-image example script and came up with this:

import QtQml 2.0
import QOwnNotesTypes 1.0

QtObject {

    function init() {
        script.registerCustomAction("pasteCodeBlock", "Paste code block", "CodeBlock", "insert-image", true);
    }

    function customActionInvoked(identifier) {
        switch (identifier) {
            case "pasteCodeBlock":
                var text = script.clipboard();

                while (text.startsWith("\n")) {
                    text = text.substr(1, text.length);
                }

                while (text.endsWith("\n")) {
                    text = text.substr(0, text.length-1);
                }

                script.noteTextEditWrite("```\n" + text + "\n```\n");
                break;

        }
    }
}

I then mapped it to Ctrl + Shift + V and remapped the default function elsewhere (btw there's no warning if shortcuts collide). Seems to do the trick. Thanks for making such a great program and further, for making it so modular (:

EDIT: Added handling for newlines.

@pbek

This comment has been minimized.

Owner

pbek commented May 15, 2018

Great! If you are choosing a better suited image as icon (there is a link to the images on http://docs.qownnotes.org/en/develop/scripting/README.html#registering-a-custom-action) you could add the script to the script repository if you want.

See: https://github.com/qownnotes/scripts/blob/master/README.md

@pbek

This comment has been minimized.

Owner

pbek commented May 15, 2018

@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2018

@maqp, it was more work than I thought, but now:

18.05.3

  • you will now get a notification if you assign a shortcut that is already
    used by an other menu item in the Shortcuts settings
@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2018

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

@maqp

This comment has been minimized.

maqp commented May 16, 2018

@pbek Yes, it works!

However, I tried checking the "don't display again" button to see what the behavior is if user then tries to assign key-combination to reserved binding. Alas, I'm not sure how to re-enable the warning. Could you make that setting a checkbox?

(Also, if it's not too much of an effort, could you please make a take me there button to the pop-up dialog that fills the name of the binding that already uses the shortcut, to the shortcut search box, or otherwise navigates to the binding, making remapping easy.

@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2018

Alas, I'm not sure how to re-enable the warning.

There is a place in the settings to reset the dialogs.

Also, if it's not too much of an effort, could you please make a take me there button to the pop-up dialog that fills the name of the binding that already uses the shortcut

Actually I would have to create a new dialog to do that... I don't know if I like to spend an other few hours on that. :)

@pbek

This comment has been minimized.

Owner

pbek commented May 16, 2018

...but I'll see.

@pbek

This comment has been minimized.

Owner

pbek commented May 17, 2018

In the end I did it... ;)

18.05.4

  • you are now able to jump to the conflicting keyboard shortcut if you assign a
    shortcut that is already used by an other menu item in the Shortcuts settings
    • the duplicate dialog if assigning a conflicting shortcut if no shortcut
      was defined before was fixed
@pbek

This comment has been minimized.

Owner

pbek commented May 17, 2018

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

@pbek pbek added enhancement scripting and removed question labels May 17, 2018

@maqp

This comment has been minimized.

maqp commented May 17, 2018

The scrolling works really well! There seems to be three cases:

  1. If the binding is visible, no scrolling takes place (this requires the most searching effort)
  2. If the binding is below active view, it appears on bottom of the active view
  3. If the binding is above active view, it appears on top of the active view

I noticed it's possible to highlight a shortcut name, so could that happen when the user jumps to the shortcut? i.e. when active view is at top, setting keybinding Ctrl+-, and choosing "jump" when prompted, jumps and shows the following

@pbek

This comment has been minimized.

Owner

pbek commented May 18, 2018

Thank you for your feedback!

@pbek

This comment has been minimized.

Owner

pbek commented May 19, 2018

18.05.5

  • a conflicting keyboard shortcut will now be highlighted if you jump to it while assigning a shortcut in the Shortcuts settings
@pbek

This comment has been minimized.

Owner

pbek commented May 19, 2018

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

@maqp

This comment has been minimized.

maqp commented May 19, 2018

It works perfectly! Thank You for for these changes!

@pbek

This comment has been minimized.

Owner

pbek commented May 19, 2018

Great, thank you for testing! :)

@maqp

This comment has been minimized.

maqp commented Jun 2, 2018

I'm not sure if it's me switching to Ubuntu 18.04 or that I did not test it properly, but it looks like 18.05.7 does not remember key-combinations assigned to shortcuts. Pressing "OK" after assigning the hotkey does nothing, and when returning to shortcuts, the program shows the function has "Undefined key".

@pbek

This comment has been minimized.

Owner

pbek commented Jun 2, 2018

That's strange, I'll take a look at that!

@pbek

This comment has been minimized.

Owner

pbek commented Jun 2, 2018

Haha, while fixing a wrong line of code back then I was breaking the storing of shortcuts, because it was relying on that wrong line. :) I fixed that one too now. Thank you for mentioning! I'll make a new release today.

pbek added a commit that referenced this issue Jun 2, 2018

pbek added a commit that referenced this issue Jun 2, 2018

@pbek

This comment has been minimized.

Owner

pbek commented Jun 2, 2018

18.06.0

  • fixed storing of keyboard shortcuts in the Shortcuts settings
@pbek

This comment has been minimized.

Owner

pbek commented Jun 2, 2018

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

@maqp

This comment has been minimized.

maqp commented Jun 3, 2018

It's working now. Thanks!

@pbek

This comment has been minimized.

Owner

pbek commented Jun 3, 2018

Great, thank you for testing!

@pbek

This comment has been minimized.

Owner

pbek commented Jun 27, 2018

I guess that's something for you, @maqp ;)

18.06.7

  • if a code block is inserted in an empty line then automatically a multi-line
    code block will be inserted instead of an inline code block

pbek added a commit that referenced this issue Jun 27, 2018

@pbek

This comment has been minimized.

Owner

pbek commented Jun 28, 2018

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

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