Skip to content

Commit

Permalink
style & feat: format codes & underline occurrence other than frame
Browse files Browse the repository at this point in the history
The occurrences were framed, but it sometimes cost a long time which is
perceptible by the users. What's worse, it sometimes needs many undos,
which is described in Megaxela#20.

After this change, the occurrences are underlined other than framed,
and the words are find by whole-word rule. This is fast and doesn't
need any undos.

It may be possible to use frames which is more beatiful without being
slow or modifying the text, but I'm just lazy to implement it.
  • Loading branch information
ouuan committed Jan 30, 2020
1 parent 9f1aa21 commit b0eb211
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 314 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ set(INCLUDE_FILES
include/QLuaCompleter
include/QLuaHighlighter
include/QPythonHighlighter
include/QFramedTextAttribute
include/internal/QHighlightRule.hpp
include/internal/QHighlightBlockRule.hpp
include/internal/QCodeEditor.hpp
Expand All @@ -47,7 +46,6 @@ set(INCLUDE_FILES
include/internal/QLuaHighlighter.hpp
include/internal/QPythonCompleter.hpp
include/internal/QPythonHighlighter.hpp
include/internal/QFramedTextAttribute.hpp
)

set(SOURCE_FILES
Expand All @@ -65,7 +63,6 @@ set(SOURCE_FILES
src/internal/QLuaHighlighter.cpp
src/internal/QPythonCompleter.cpp
src/internal/QPythonHighlighter.cpp
src/internal/QFramedTextAttribute.cpp
)

# Create code for QObjects
Expand Down
3 changes: 0 additions & 3 deletions include/QFramedTextAttribute

This file was deleted.

75 changes: 29 additions & 46 deletions include/internal/QCodeEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ class QCodeEditor : public QTextEdit
{
Q_OBJECT

public:
public:
/**
* @brief Constructor.
* @param widget Pointer to parent widget.
*/
explicit QCodeEditor(QWidget* widget=nullptr);
explicit QCodeEditor(QWidget *widget = nullptr);

// Disable copying
QCodeEditor(const QCodeEditor&) = delete;
QCodeEditor& operator=(const QCodeEditor&) = delete;
QCodeEditor(const QCodeEditor &) = delete;
QCodeEditor &operator=(const QCodeEditor &) = delete;

/**
* @brief Method for getting first visible block
Expand All @@ -38,13 +38,13 @@ class QCodeEditor : public QTextEdit
* @brief Method for setting highlighter.
* @param highlighter Pointer to syntax highlighter.
*/
void setHighlighter(QStyleSyntaxHighlighter* highlighter);
void setHighlighter(QStyleSyntaxHighlighter *highlighter);

/**
* @brief Method for setting syntax sty.e.
* @param style Pointer to syntax style.
*/
void setSyntaxStyle(QSyntaxStyle* style);
void setSyntaxStyle(QSyntaxStyle *style);

/**
* @brief Method setting auto parentheses enabled.
Expand Down Expand Up @@ -98,15 +98,15 @@ class QCodeEditor : public QTextEdit
* @brief Method for setting completer.
* @param completer Pointer to completer object.
*/
void setCompleter(QCompleter* completer);
void setCompleter(QCompleter *completer);

/**
* @brief Method for getting completer.
* @return Pointer to completer.
*/
QCompleter* completer() const;
QCompleter *completer() const;

public Q_SLOTS:
public Q_SLOTS:

/**
* @brief Slot, that performs insertion of
Expand All @@ -127,45 +127,40 @@ public Q_SLOTS:
* part of line number area.
* @param rect Area that has to be updated.
*/
void updateLineNumberArea(const QRect& rect);
void updateLineNumberArea(const QRect &rect);

/**
* @brief Slot, that will proceed extra selection
* for current cursor position.
*/
void updateExtraSelection();
void updateExtraSelection1();
void updateExtraSelection2();

/**
* @brief Slot, that will update editor style.
*/
void updateStyle();

/**
* @brief Slot, that will be called on selection
* change.
*/
void onSelectionChanged();

protected:
protected:
/**
* @brief Method, that's called on any text insertion of
* mimedata into editor. If it's text - it inserts text
* as plain text.
*/
void insertFromMimeData(const QMimeData* source) override;
void insertFromMimeData(const QMimeData *source) override;

/**
* @brief Method, that's called on editor painting. This
* method if overloaded for line number area redraw.
*/
void paintEvent(QPaintEvent* e) override;
void paintEvent(QPaintEvent *e) override;

/**
* @brief Method, that's called on any widget resize.
* This method if overloaded for line number area
* resizing.
*/
void resizeEvent(QResizeEvent* e) override;
void resizeEvent(QResizeEvent *e) override;

/**
* @brief Method, that's called on any key press, posted
Expand All @@ -176,7 +171,7 @@ public Q_SLOTS:
* 3. Low indentation
* 4. Auto parenthesis
*/
void keyPressEvent(QKeyEvent* e) override;
void keyPressEvent(QKeyEvent *e) override;

/**
* @brief Method, that's called on focus into widget.
Expand All @@ -185,14 +180,7 @@ public Q_SLOTS:
*/
void focusInEvent(QFocusEvent *e) override;

private:

/**
* @brief Method for initializing document
* layout handlers.
*/
void initDocumentLayoutHandlers();

private:
/**
* @brief Method for initializing default
* monospace font.
Expand All @@ -205,12 +193,6 @@ public Q_SLOTS:
*/
void performConnections();

/**
* @brief Method, that performs selection
* frame selection.
*/
void handleSelectionQuery(QTextCursor cursor);

/**
* @brief Method for updating geometry of line number area.
*/
Expand All @@ -223,7 +205,7 @@ public Q_SLOTS:
* @return Shall event be dropped.
*/
bool proceedCompleterBegin(QKeyEvent *e);
void proceedCompleterEnd(QKeyEvent* e);
void proceedCompleterEnd(QKeyEvent *e);

/**
* @brief Method for getting character under
Expand All @@ -243,13 +225,15 @@ public Q_SLOTS:
* @brief Method, that adds highlighting of
* currently selected line to extra selection list.
*/
void highlightCurrentLine(QList<QTextEdit::ExtraSelection>& extraSelection);
void highlightCurrentLine();

/**
* @brief Method, that adds highlighting of
* parenthesis if available.
*/
void highlightParenthesis(QList<QTextEdit::ExtraSelection>& extraSelection);
void highlightParenthesis();

void highlightOccurrences();

/**
* @brief Method for getting number of indentation
Expand All @@ -258,16 +242,15 @@ public Q_SLOTS:
*/
int getIndentationSpaces();

QStyleSyntaxHighlighter* m_highlighter;
QSyntaxStyle* m_syntaxStyle;
QLineNumberArea* m_lineNumberArea;
QCompleter* m_completer;

QFramedTextAttribute* m_framedAttribute;
QStyleSyntaxHighlighter *m_highlighter;
QSyntaxStyle *m_syntaxStyle;
QLineNumberArea *m_lineNumberArea;
QCompleter *m_completer;

bool m_autoIndentation;
bool m_autoParentheses;
bool m_replaceTab;
QString m_tabReplace;
};

QList<QTextEdit::ExtraSelection> extra1, extra2;
};
88 changes: 0 additions & 88 deletions include/internal/QFramedTextAttribute.hpp

This file was deleted.

Loading

0 comments on commit b0eb211

Please sign in to comment.