edbee / edbee-lib

QWidget based Text Editor Component for Qt. Multi-caret, Textmate grammar and highlighting support.
Other
75 stars 26 forks source link

Recommended way to set current line #104

Closed emoon closed 4 years ago

emoon commented 4 years ago

Hi,

I wonder what the current recommended way is to update the current line (for the caret) and to make sure that it's centered on the screen (if possible) Imagine how a debugger works when you step and you want to updated the location from "outside"

gamecreature commented 4 years ago

Hi Daniel, I guess the easiest way is to look at the Edbee-app sample, gotowidget. https://github.com/edbee/edbee-app/blob/master/edbee-app/ui/gotowidget.cpp

It has a goto line function .

It uses the controller function to move the caret. (It makes sure the caret is placed inside the document)

edbee::TextEditorController* controller = editorRef_->controller();
controller->moveCaretTo(line,column,false);
controller->scrollCaretVisible();

Internally the command used (by moveCaretTo) is the following. The editor works with commands which can be passed to 'executeCommand'.

SelectionCommand command( SelectionCommand::MoveCaretToExactOffset, offset, keepAnchors, rangeIndex );
executeCommand( &command );

Best Regards, Rick

emoon commented 4 years ago

Great! Thanks :)

emoon commented 4 years ago

This works great! Just another question: What is the best way to clear all text? I figured one way would be to select all text and doing a cut, but I figured there would be a better way to do it? What I tried to do is editor->textDocument()->lineDataManager()->clear(); but when trying to insert some new data I get an assert.

vadi2 commented 4 years ago

This should be a separate question so we don't start a thread of questions here :)

We use the following: https://github.com/Mudlet/Mudlet/blob/development/src/dlgTriggerEditor.cpp#L8692

emoon commented 4 years ago

Closing this one now also as the original question has an answer now :)