This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Problem with Kate Script view.selection()

Tags: None
(comma "," separated)
loma
Registered Member
Posts
4
Karma
0
I am writing a small Kate script to add line numbers at the beginning of each line within selection.
However, the view.selection() always returns
ReferenceError: Range is not defined


The other calls view.hasSelection() and view.selectedText() are giving the correct results (e.g. True and the text within selection respectively).

Any help will be appreciated.
User avatar
pvzh
Registered Member
Posts
24
Karma
1
OS
Interesting problem. I decided to check, it works for me on Kate 19.12.3:

Code: Select all
function addLineNumbers() {
    if (!view.hasSelection()) return;
    var selection = view.selection();

    var text = view.selectedText()
        .split('\n')
        .map((v, i) => i + ' ' + v)
        .join('\n');

    document.editBegin();
    document.removeText(selection);
    document.insertText(selection.start, text);
    document.editEnd();
}
loma
Registered Member
Posts
4
Karma
0
Thanks @pvzh

I tried your code, but getting the same error with Kate version 22.04.3.
debug(selection) gives "ReferenceError: Range is not defined" and selection.start "undefined"


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]