[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ktexteditor/multicursor] src: Merge branch 'master' into multicursor
From:       Sven Brauch <null () kde ! org>
Date:       2018-08-13 8:44:02
Message-ID: E1fp8SI-00064I-Qa () code ! kde ! org
[Download RAW message or body]

Git commit d40056b534cba87ec8852199fad2b892e32e2e09 by Sven Brauch.
Committed on 13/08/2018 at 08:37.
Pushed by brauch into branch 'multicursor'.

Merge branch 'master' into multicursor

M  +1    -0    src/CMakeLists.txt
M  +74   -63   src/document/katedocument.cpp
M  +8    -5    src/render/katerenderer.cpp
M  +54   -0    src/script/katescripteditor.cpp
M  +14   -17   src/search/katesearchbar.cpp
M  +25   -25   src/undo/kateundo.h
M  +6    -0    src/utils/kateglobal.cpp
M  +12   -12   src/utils/kateglobal.h
M  +12   -9    src/view/kateview.cpp
M  +60   -60   src/view/kateview.h
M  +73   -26   src/view/kateviewaccessible.h
M  +12   -5    src/view/kateviewhelpers.cpp
M  +31   -9    src/view/kateviewinternal.cpp
M  +25   -23   src/view/kateviewinternal.h

https://commits.kde.org/ktexteditor/d40056b534cba87ec8852199fad2b892e32e2e09

diff --cc src/document/katedocument.cpp
index 9cd7c14d,e272df50..1e7320ba
--- a/src/document/katedocument.cpp
+++ b/src/document/katedocument.cpp
@@@ -3080,27 -3090,27 +3086,29 @@@ void KTextEditor::DocumentPrivate::newL
      }
  
      // query cursor position
 -    KTextEditor::Cursor c = v->cursorPosition();
 -
 -    if (c.line() > lastLine()) {
 -        c.setLine(lastLine());
 -    }
 +    Q_FOREACH ( auto c, v->allCursors() ) {
-         if (c.line() > (int)lastLine()) {
++        if (c.line() > lastLine()) {
 +            c.setLine(lastLine());
 +        }
  
 -    if (c.line() < 0) {
 -        c.setLine(0);
 -    }
 +        if (c.line() < 0) {
 +            c.setLine(0);
 +        }
  
 -    int ln = c.line();
 +        uint ln = c.line();
  
 -    Kate::TextLine textLine = plainKateTextLine(ln);
 +        Kate::TextLine textLine = plainKateTextLine(ln);
- 
 +        if (c.column() > (int)textLine->length()) {
 +            c.setColumn(textLine->length());
 +        }
  
 -    if (c.column() > textLine->length()) {
 -        c.setColumn(textLine->length());
 +        // first: wrap line
 +        editWrapLine(c.line(), c.column());
++        if (c.column() > textLine->length()) {
++            c.setColumn(textLine->length());
++        }
      }
  
 -    // first: wrap line
 -    editWrapLine(c.line(), c.column());
 -
      // end edit session here, to have updated HL in userTypedChar!
      editEnd();
  
diff --cc src/render/katerenderer.cpp
index c7ae2d47,fdb29840..d1158518
--- a/src/render/katerenderer.cpp
+++ b/src/render/katerenderer.cpp
@@@ -782,88 -768,80 +782,89 @@@ void KateRenderer::paintTextLine(QPaint
          }
  
          // Draw caret
 -        if (drawCaret() && cursor && range->includesCursor(*cursor)) {
 -            int caretWidth, lineWidth = 2;
 -            QColor color;
 -            QTextLine line = \
                range->layout()->lineForTextPosition(qMin(cursor->column(), \
                range->length()));
 -
 -            // Determine the caret's style
 -            caretStyles style = caretStyle();
 -
 -            // Make the caret the desired width
 -            if (style == Line) {
 -                caretWidth = lineWidth;
 -            } else if (line.isValid() && cursor->column() < range->length()) {
 -                caretWidth = int(line.cursorToX(cursor->column() + 1) - \
                line.cursorToX(cursor->column()));
 -                if (caretWidth < 0) {
 -                    caretWidth = -caretWidth;
 +        auto drawCaretAt = [this, &range, &paint, &xEnd, &xStart](const \
KTextEditor::Cursor* cursor, int alpha=255) {  +            if (drawCaret() && cursor \
&& range->includesCursor(*cursor)) {  +                int caretWidth, lineWidth = 2;
 +                QColor color;
 +                QTextLine line = \
range->layout()->lineForTextPosition(qMin(cursor->column(), range->length()));  +
 +                // Determine the caret's style
 +                caretStyles style = caretStyle();
 +
 +                // Make the caret the desired width
 +                if (style == Line) {
 +                    caretWidth = lineWidth;
 +                } else if (line.isValid() && cursor->column() < range->length()) {
 +                    caretWidth = int(line.cursorToX(cursor->column() + 1) - \
line.cursorToX(cursor->column()));  +                    if (caretWidth < 0) {
 +                        caretWidth = -caretWidth;
 +                    }
 +                } else {
 +                    caretWidth = spaceWidth();
                  }
 -            } else {
 -                caretWidth = spaceWidth();
 -            }
  
 -            // Determine the color
 -            if (m_caretOverrideColor.isValid()) {
 -                // Could actually use the real highlighting system for this...
 -                // would be slower, but more accurate for corner cases
 -                color = m_caretOverrideColor;
 -            } else {
 -                // search for the FormatRange that includes the cursor
 -                foreach (const QTextLayout::FormatRange &r, \
                range->layout()->additionalFormats()) {
 -                    if ((r.start <= cursor->column()) && ((r.start + r.length)  > \
                cursor->column())) {
 -                        // check for Qt::NoBrush, as the returned color is black() \
                and no invalid QColor
 -                        QBrush foregroundBrush = r.format.foreground();
 -                        if (foregroundBrush != Qt::NoBrush) {
 -                            color = r.format.foreground().color();
 +                // Determine the color
 +                if (m_caretOverrideColor.isValid()) {
 +                    // Could actually use the real highlighting system for this...
 +                    // would be slower, but more accurate for corner cases
 +                    color = m_caretOverrideColor;
 +                } else {
 +                    // search for the FormatRange that includes the cursor
 +                    foreach (const QTextLayout::FormatRange &r, \
range->layout()->additionalFormats()) {  +                        if ((r.start <= \
cursor->column()) && ((r.start + r.length)  > cursor->column())) {  +                 \
// check for Qt::NoBrush, as the returned color is black() and no invalid QColor  +   \
QBrush foregroundBrush = r.format.foreground();  +                            if \
(foregroundBrush != Qt::NoBrush) {  +                                color = \
r.format.foreground().color();  +                            }
 +                            break;
                          }
 -                        break;
 +                    }
 +                    // still no color found, fall back to default style
 +                    if (!color.isValid()) {
 +                        color = \
attribute(KTextEditor::dsNormal)->foreground().color();  }
                  }
 -                // still no color found, fall back to default style
 -                if (!color.isValid()) {
 -                    color = attribute(KTextEditor::dsNormal)->foreground().color();
 -                }
 -            }
  
 -            paint.save();
 -            paint.setRenderHint(QPainter::Antialiasing, false);
 -            switch (style) {
 -            case Line :
 -                paint.setPen(QPen(color, caretWidth));
 -                break;
 -            case Block :
 -                // use a gray caret so it's possible to see the character
 -                color.setAlpha(128);
 -                paint.setPen(QPen(color, caretWidth));
 -                break;
 -            case Underline :
 -                break;
 -            case Half :
 -                color.setAlpha(128);
 -                paint.setPen(QPen(color, caretWidth));
 -                break;
 -            }
 +                paint.save();
++                paint.setRenderHint(QPainter::Antialiasing, false);
 +                switch (style) {
 +                case Line :
 +                    paint.setPen(QPen(color, caretWidth));
 +                    break;
 +                case Block :
 +                    // use a gray caret so it's possible to see the character
 +                    color.setAlpha(128);
 +                    paint.setPen(QPen(color, caretWidth));
 +                    break;
 +                case Underline :
 +                    break;
 +                case Half :
 +                    color.setAlpha(128);
 +                    paint.setPen(QPen(color, caretWidth));
 +                    break;
 +                }
  
 -            if (cursor->column() <= range->length()) {
 -                range->layout()->drawCursor(&paint, QPoint(-xStart, 0), \
                cursor->column(), caretWidth);
 -            } else {
 -                // Off the end of the line... must be block mode. Draw the caret \
                ourselves.
 -                const KateTextLayout &lastLine = \
                range->viewLine(range->viewLineCount() - 1);
 -                int x = cursorToX(lastLine, KTextEditor::Cursor(range->line(), \
                cursor->column()), true);
 -                if ((x >= xStart) && (x <= xEnd)) {
 -                    paint.fillRect(x - xStart, (int)lastLine.lineLayout().y(), \
caretWidth, lineHeight(), color);  +                if (cursor->column() <= \
range->length()) {  +                    range->layout()->drawCursor(&paint, \
QPoint(-xStart, 0), cursor->column(), caretWidth);  +                } else {
 +                    // Off the end of the line... must be block mode. Draw the \
caret ourselves.  +                    const KateTextLayout &lastLine = \
range->viewLine(range->viewLineCount() - 1);  +                    int x = \
cursorToX(lastLine, KTextEditor::Cursor(range->line(), cursor->column()), true);  +   \
if ((x >= xStart) && (x <= xEnd)) {  +                        paint.fillRect(x - \
xStart, (int)lastLine.lineLayout().y(), caretWidth, lineHeight(), color);  +          \
}  }
 -            }
  
 -            paint.restore();
 +                paint.restore();
 +            }
 +        };
 +        drawCaretAt(cursor);
 +        foreach ( const auto& secondary, view()->cursors()->cursors() ) {
 +            if ( cursor && secondary == *cursor ) {
 +                continue;
 +            }
 +            drawCaretAt(&secondary, 128);
          }
      }
  
diff --cc src/script/katescripteditor.cpp
index 00000000,29c54ded..92694b27
mode 000000,100644..100644
--- a/src/script/katescripteditor.cpp
+++ b/src/script/katescripteditor.cpp
@@@ -1,0 -1,50 +1,54 @@@
+ /* This file is part of the KDE libraries.
+  *
+  * Copyright (C) 2017 Dominik Haumann <dhaumann@kde.org>
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Library General Public
+  * License as published by the Free Software Foundation; either
+  * version 2 of the License, or (at your option) any later version.
+  *
+  * This library is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  * Library General Public License for more details.
+  *
+  * You should have received a copy of the GNU Library General Public License
+  * along with this library; see the file COPYING.LIB.  If not, write to
+  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+  * Boston, MA 02110-1301, USA.
+  */
+ 
+ #include "katescripteditor.h"
+ 
+ #include "kateglobal.h"
+ 
+ #include <QApplication>
+ #include <QClipboard>
+ #include <QJSEngine>
+ 
+ using KTextEditor::EditorPrivate;
+ 
+ KateScriptEditor::KateScriptEditor(QJSEngine *engine, QObject *parent)
+     : QObject(parent)
+     , m_engine(engine)
+ {
+ }
+ 
+ QString KateScriptEditor::clipboardText() const
+ {
+     return QApplication::clipboard()->text();
+ }
+ 
+ QStringList KateScriptEditor::clipboardHistory() const
+ {
 -    return KTextEditor::EditorPrivate::self()->clipboardHistory();
++    QStringList ret;
++    for ( const auto& entry: KTextEditor::EditorPrivate::self()->clipboardHistory() \
) { ++        ret.append(entry.isEmpty() ? QString() : entry.first());
++    }
++    return ret;
+ }
+ 
+ void KateScriptEditor::setClipboardText(const QString &text)
+ {
 -    KTextEditor::EditorPrivate::self()->copyToClipboard(text);
++    QApplication::clipboard()->setText(text, QClipboard::Clipboard);
+ }
diff --cc src/utils/kateglobal.cpp
index d1ed531d,a95adec4..8be64f65
--- a/src/utils/kateglobal.cpp
+++ b/src/utils/kateglobal.cpp
@@@ -466,9 -466,15 +466,15 @@@ void KTextEditor::EditorPrivate::update
      }
  
      /**
 -     * move to clipboard
 +     * remember in history
+      */
 -    QApplication::clipboard()->setText(text, QClipboard::Clipboard);
++    QApplication::clipboard()->setText(text.first(), QClipboard::Clipboard);
+ 
+     /**
+      * LRU, kill potential duplicated, move new entry to top
       * cut after 10 entries
       */
+     m_clipboardHistory.removeOne(text);
      m_clipboardHistory.prepend(text);
      if (m_clipboardHistory.size() > 10) {
          m_clipboardHistory.removeLast();
diff --cc src/utils/kateglobal.h
index c8224575,416773ff..4f1416a6
--- a/src/utils/kateglobal.h
+++ b/src/utils/kateglobal.h
@@@ -363,13 -363,13 +363,13 @@@ public
       * Get a list of available commandline strings.
       * \return commandline strings
       */
-     QStringList commandList() const Q_DECL_OVERRIDE;
+     QStringList commandList() const override;
  
      /**
 -     * Copy text to clipboard an remember it in the history
 -     * @param text text to copy to clipboard, does nothing if empty!
 +     * Remember text in the clipboard history
 +     * @param text text to remember, does nothing if empty!
       */
 -    void copyToClipboard(const QString &text);
 +    void updateClipboardHistory(const QVector<QString> &text);
  
      /**
       * Clipboard history, filled with text we ever copied
diff --cc src/view/kateview.h
index 04342736,359be8ac..d07cbb6d
--- a/src/view/kateview.h
+++ b/src/view/kateview.h
@@@ -167,19 -152,17 +167,19 @@@ private
      // KTextEditor::ViewCursorInterface
      //
  public:
-     bool setCursorPosition(KTextEditor::Cursor position) Q_DECL_OVERRIDE;
-     bool setCursorPositions(const QVector<KTextEditor::Cursor> &positions) \
Q_DECL_OVERRIDE; +     bool setCursorPosition(KTextEditor::Cursor position) override;
++    bool setCursorPositions(const QVector<KTextEditor::Cursor> &positions) \
override;  
-     KTextEditor::Cursor cursorPosition() const Q_DECL_OVERRIDE;
-     QVector<KTextEditor::Cursor> cursorPositions() const Q_DECL_OVERRIDE;
+     KTextEditor::Cursor cursorPosition() const override;
++    QVector<KTextEditor::Cursor> cursorPositions() const override;
  
-     KTextEditor::Cursor cursorPositionVirtual() const Q_DECL_OVERRIDE;
+     KTextEditor::Cursor cursorPositionVirtual() const override;
  
-     QPoint cursorToCoordinate(const KTextEditor::Cursor &cursor) const \
Q_DECL_OVERRIDE; +     QPoint cursorToCoordinate(const KTextEditor::Cursor &cursor) \
const override;  
-     KTextEditor::Cursor coordinatesToCursor(const QPoint &coord) const \
Q_DECL_OVERRIDE; +     KTextEditor::Cursor coordinatesToCursor(const QPoint &coord) \
const override;  
-     QPoint cursorPositionCoordinates() const Q_DECL_OVERRIDE;
+     QPoint cursorPositionCoordinates() const override;
  
      bool setCursorPositionVisual(const KTextEditor::Cursor &position);
  
@@@ -271,27 -254,9 +271,27 @@@ public
      // KTextEditor::SelectionInterface stuff
      //
  public Q_SLOTS:
 +    /**
 +     * @brief Get the primary selection.
 +     *
 +     * The primary selection is the selection range containing the primary
 +     * cursor. If no such selection exists, as might be the case
 +     * in "persistent selection" mode, the persistent selection is returned \
instead.  +     */
 +    KTextEditor::Range primarySelection() const {
 +        return selections()->primarySelection();
 +    };
 +    /**
 +     * @brief Set the primary selection.
 +     */
-     bool setSelection(const KTextEditor::Range &selection) Q_DECL_OVERRIDE;
+     bool setSelection(const KTextEditor::Range &selection) override;
 +    bool setPrimarySelection(const KTextEditor::Range &selection) {
 +        return setSelection(selection);
 +    };
 +    bool setSelections(const QVector<KTextEditor::Range> &selections,
-                        const QVector<KTextEditor::Cursor> &cursors) \
Q_DECL_OVERRIDE; ++                       const QVector<KTextEditor::Cursor> \
&cursors) override;  
-     bool removeSelection() Q_DECL_OVERRIDE
+     bool removeSelection() override
      {
          return clearSelection();
      }
@@@ -301,9 -266,8 +301,9 @@@
          return removeSelectedText();
      }
  
-     bool setBlockSelection(bool on) Q_DECL_OVERRIDE;
+     bool setBlockSelection(bool on) override;
      bool toggleBlockSelection();
 +    bool toAlignedBlock(bool fill);
  
      bool clearSelection();
      bool clearSelection(bool redraw, bool finishedChangingSelection = true);
@@@ -313,11 -277,10 +313,11 @@@
      bool selectAll();
  
  public:
-     bool selection() const Q_DECL_OVERRIDE;
-     QString selectionText() const Q_DECL_OVERRIDE;
-     bool blockSelection() const Q_DECL_OVERRIDE;
-     KTextEditor::Range selectionRange() const Q_DECL_OVERRIDE;
-     QVector<KTextEditor::Range> selectionRanges() const Q_DECL_OVERRIDE;
+     bool selection() const override;
+     QString selectionText() const override;
+     bool blockSelection() const override;
+     KTextEditor::Range selectionRange() const override;
++    QVector<KTextEditor::Range> selectionRanges() const override;
  
      static void blockFix(KTextEditor::Range &range);
  
diff --cc src/view/kateviewaccessible.h
index c3387008,51dfda77..4e3257e3
--- a/src/view/kateviewaccessible.h
+++ b/src/view/kateviewaccessible.h
@@@ -125,12 -130,12 +130,12 @@@ public
          QPoint size = view()->cursorToCoordinate(endCursor) - p;
          return QRect(view()->mapToGlobal(p), QSize(size.x(), size.y()));
      }
-     int cursorPosition() const Q_DECL_OVERRIDE
+     int cursorPosition() const override
      {
 -        KTextEditor::Cursor c = view()->getCursor();
 +        KTextEditor::Cursor c = view()->primaryCursor();
          return positionFromCursor(view(), c);
      }
-     int offsetAtPoint(const QPoint & /*point*/) const Q_DECL_OVERRIDE
+     int offsetAtPoint(const QPoint & /*point*/) const override
      {
          return 0;
      }
diff --cc src/view/kateviewinternal.cpp
index c92cf272,f9dd3685..b589f185
--- a/src/view/kateviewinternal.cpp
+++ b/src/view/kateviewinternal.cpp
@@@ -2783,9 -3353,10 +2789,10 @@@ void KateViewInternal::clear(
  {
      m_startPos.setPosition(0, 0);
      m_displayCursor = KTextEditor::Cursor(0, 0);
 -    m_cursor.setPosition(0, 0);
 +    primaryCursor().setPosition(0, 0);
      cache()->clear();
      updateView(true);
+     m_lineScroll->updatePixmap();
  }
  
  void KateViewInternal::wheelEvent(QWheelEvent *e)
@@@ -3044,8 -3634,10 +3064,10 @@@ void KateViewInternal::cursorMoved(
      m_view->updateRangesIn(KTextEditor::Attribute::ActivateCaretIn);
  
  #ifndef QT_NO_ACCESSIBILITY
-     QAccessibleTextCursorEvent ev(this, \
                KateViewAccessible::positionFromCursor(this, primaryCursor()));
-     QAccessible::updateAccessibility(&ev);
+     if (QAccessible::isActive()) {
 -        QAccessibleTextCursorEvent ev(this, static_cast<KateViewAccessible \
*>(QAccessible::queryAccessibleInterface(this))->positionFromCursor(this, m_cursor)); \
++        QAccessibleTextCursorEvent ev(this, static_cast<KateViewAccessible \
*>(QAccessible::queryAccessibleInterface(this))->positionFromCursor(this, \
primaryCursor())); +         QAccessible::updateAccessibility(&ev);
+     }
  #endif
  }
  
diff --cc src/view/kateviewinternal.h
index bce1eb65,4d26dbc9..11c9ad04
--- a/src/view/kateviewinternal.h
+++ b/src/view/kateviewinternal.h
@@@ -269,11 -267,10 +269,12 @@@ private
      void updateSelection(const KTextEditor::Cursor &, bool keepSel);
      void setSelection(const KTextEditor::Range &);
      void moveCursorToSelectionEdge();
 -    void updateCursor(const KTextEditor::Cursor &newCursor, bool force = false, \
bool center = false, bool calledExternally = false);  +    void \
notifyPrimaryCursorChanged(const KTextEditor::Cursor &newCursor, bool force = false, \
bool center = false, bool calledExternally = false);  +    void \
updateCursorFlashTimer();  void updateBracketMarks();
+     void beginSelectLine(const QPoint &pos);
  
 +    KTextEditor::Cursor pointToCursor(const QPoint& p) const;
      void placeCursor(const QPoint &p, bool keepSelection = false, bool \
updateSelection = true);  bool isTargetSelected(const QPoint &p);
      //Returns whether the given range affects the area currently visible in the \
view @@@ -459,11 -442,8 +461,11 @@@ private
      // IM input stuff
      //
  public:
-     QVariant inputMethodQuery(Qt::InputMethodQuery query) const Q_DECL_OVERRIDE;
+     QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
  
 +public:
 +    void notifyLinesUpdated(const QVector<KTextEditor::Cursor>& changed);
 +
  private:
      KTextEditor::MovingRange *m_imPreeditRange;
      QList<KTextEditor::MovingRange *> m_imPreeditRangeChildren;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic