Skip to content

Commit

Permalink
pbek/QOwnNotes#3208 add: more read-only checks
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <[email protected]>
  • Loading branch information
pbek committed Jan 15, 2025
1 parent 14fd3a9 commit 4864cb2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions qmarkdowntextedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,14 @@ bool QMarkdownTextEdit::eventFilter(QObject *obj, QEvent *event) {
return bracketClosingCheck(QLatin1Char('<'), QLatin1Char('>'));
} else if ((keyEvent->key() == Qt::Key_Return ||
keyEvent->key() == Qt::Key_Enter) &&
!isReadOnly() &&
keyEvent->modifiers().testFlag(Qt::ShiftModifier)) {
QTextCursor cursor = this->textCursor();
cursor.insertText(" \n");
return true;
} else if ((keyEvent->key() == Qt::Key_Return ||
keyEvent->key() == Qt::Key_Enter) &&
!isReadOnly() &&
keyEvent->modifiers().testFlag(Qt::ControlModifier)) {
QTextCursor cursor = this->textCursor();
cursor.movePosition(QTextCursor::EndOfBlock);
Expand Down Expand Up @@ -560,6 +562,10 @@ void QMarkdownTextEdit::centerTheCursor() {
* bracket closing was used otherwise performs normal undo
*/
void QMarkdownTextEdit::undo() {
if (isReadOnly()) {
return;
}

QTextCursor cursor = textCursor();
// if no text selected, call undo
if (!cursor.hasSelection()) {
Expand Down Expand Up @@ -589,6 +595,10 @@ void QMarkdownTextEdit::undo() {
}

void QMarkdownTextEdit::moveTextUpDown(bool up) {
if (isReadOnly()) {
return;
}

QTextCursor cursor = textCursor();
QTextCursor move = cursor;

Expand Down Expand Up @@ -1391,6 +1401,10 @@ QString QMarkdownTextEdit::getMarkdownUrlAtPosition(const QString &text,
* @brief Duplicates the text in the text edit
*/
void QMarkdownTextEdit::duplicateText() {
if (isReadOnly()) {
return;
}

QTextCursor cursor = this->textCursor();
QString selectedText = cursor.selectedText();

Expand Down

0 comments on commit 4864cb2

Please sign in to comment.