Skip to content

Commit

Permalink
Improves #82, Ctrl+Drag mouse while expands the last caret (allows mu…
Browse files Browse the repository at this point in the history
…ltiple caret selections with mouse).
  • Loading branch information
gamecreature committed Mar 5, 2019
1 parent d7a6c96 commit 2436c23
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

edbee.lib:

- Improves #82, Ctrl+Drag mouse while expands the last caret (allows multiple caret selections with mouse).
- fix #79, Using backtab on empty document causes Q_ASSERT failure
- ref #66, Automatic grouping of Changes that happen in repond of another event. (Crash in setText())
- add #60, Basic support for auto complete.
Expand Down
11 changes: 8 additions & 3 deletions edbee-lib/edbee/commands/selectioncommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ namespace edbee {
/// @param unit the unit of this command
/// @param amount the number of steps
/// @param keepSelection when true the anchor stays put (and the selection is expanded)
SelectionCommand::SelectionCommand( SelectionType unit, int amount, bool keepSelection )
SelectionCommand::SelectionCommand(SelectionType unit, int amount, bool keepSelection , int rangeIndex)
: unit_(unit)
, amount_(amount)
, keepSelection_(keepSelection)
, rangeIndex_(rangeIndex)
{
}

Expand Down Expand Up @@ -118,8 +119,12 @@ void SelectionCommand::execute( TextEditorController* controller )
break;
}
case MoveCaretToExactOffset:
sel->toSingleRange();
sel->range(0).setCaret(amount_);
if( rangeIndex_ >= 0 ) {
sel->range(rangeIndex_).setCaret(amount_);
} else {
sel->toSingleRange();
sel->range(0).setCaret(amount_);
}
break;

case SelectAll:
Expand Down
6 changes: 3 additions & 3 deletions edbee-lib/edbee/commands/selectioncommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class EDBEE_EXPORT SelectionCommand : public TextEditorCommand
};

public:
explicit SelectionCommand( SelectionType unit, int amount=0, bool keepSelection=false );
explicit SelectionCommand( SelectionType unit, int amount=0, bool keepSelection=false, int rangeIndex = -1 );
virtual ~SelectionCommand();

virtual int commandId();
Expand All @@ -56,14 +56,14 @@ class EDBEE_EXPORT SelectionCommand : public TextEditorCommand
SelectionType unit() { return unit_; }
int amount() { return amount_; }
bool keepSelection() { return keepSelection_; }
int rangeIndex() { return rangeIndex_; }

private:

SelectionType unit_;
int amount_;
bool keepSelection_;


int rangeIndex_;
};


Expand Down
11 changes: 7 additions & 4 deletions edbee-lib/edbee/texteditorcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,9 @@ void TextEditorController::replaceRangeSet(TextRangeSet& rangeSet, const QString
/// For example:
/// moveCaretTo( 2, 1 ) => Moves the caret to the 3rd line and 2nd column
/// moveCaretTo( -1, -2 ) => Moves the caret to the character before the last character
void TextEditorController::moveCaretTo(int line, int col, bool keepAnchors )
///
/// The rangeIndex is used to specify which range to move.. (Defaults to -1 which changes to a single range)
void TextEditorController::moveCaretTo(int line, int col, bool keepAnchors, int rangeIndex )
{
if( line < 0) {
line = textDocument()->lineCount() + line;
Expand All @@ -638,17 +640,18 @@ void TextEditorController::moveCaretTo(int line, int col, bool keepAnchors )

//textDocument()->offsetFromLineAndColumn(line,col)

return moveCaretToOffset( offset , keepAnchors );
return moveCaretToOffset( offset , keepAnchors, rangeIndex );
}


/// Moves the caret to the given offset
/// @param offset the offset to move the caret to
/// @param keepAnchors should the anchors stay at the current position (extending the selection range)
void TextEditorController::moveCaretToOffset(int offset, bool keepAnchors)
/// The rangeIndex is used to specify which range to move.. (Defaults to -1 which changes to a single range)
void TextEditorController::moveCaretToOffset(int offset, bool keepAnchors, int rangeIndex)
{
// SelectionCommand* command = new SelectionCommand( SelectionCommand::MoveCaretToExactOffset, offset, keepAnchors );
SelectionCommand command( SelectionCommand::MoveCaretToExactOffset, offset, keepAnchors );
SelectionCommand command( SelectionCommand::MoveCaretToExactOffset, offset, keepAnchors, rangeIndex );
return executeCommand( &command );
}

Expand Down
4 changes: 2 additions & 2 deletions edbee-lib/edbee/texteditorcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public slots:
virtual void replaceRangeSet(TextRangeSet& rangeSet, const QStringList& texts, int coalesceId=0 );

// caret movements
virtual void moveCaretTo( int line, int col, bool keepAnchors );
virtual void moveCaretToOffset( int offset, bool keepAnchors );
virtual void moveCaretTo( int line, int col, bool keepAnchors, int rangeIndex=-1 );
virtual void moveCaretToOffset( int offset, bool keepAnchors, int rangeIndex=-1 );
virtual void addCaretAt( int line, int col);
virtual void addCaretAtOffset( int offset );
virtual void changeAndGiveTextSelection(TextRangeSet* rangeSet , int coalesceId = 0);
Expand Down
8 changes: 5 additions & 3 deletions edbee-lib/edbee/views/components/texteditorcomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,6 @@ void TextEditorComponent::mouseMoveEvent(QMouseEvent* event )
if( event->buttons() & Qt::LeftButton ) {
TextRenderer* renderer = textRenderer();

// int x = renderer->widgetXToXpos( event->x() + horizontalScrollBar()->value() );
// int y = renderer->widgetYToYpos( event->y() + verticalScrollBar()->value() );
int x = event->x();
int y = event->y();

Expand All @@ -462,7 +460,11 @@ void TextEditorComponent::mouseMoveEvent(QMouseEvent* event )
if( line >= 0 ) { col = renderer->columnIndexForXpos( line, x ); }
if( line < 0 ) { line = 0; }

controller()->moveCaretTo( line, col, true );
if( event->modifiers() & Qt::ControlModifier) {
controller()->moveCaretTo( line, col, true, controller()->textSelection()->rangeCount() - 1 );
} else {
controller()->moveCaretTo( line, col, true );
}
}
QWidget::mouseMoveEvent(event);
}
Expand Down

0 comments on commit 2436c23

Please sign in to comment.