View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0015600 | Scribus | Story Editor / Text Frames | public | 2019-03-13 16:12 | 2024-06-17 14:47 |
Reporter | ale | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | always |
Status | new | Resolution | open | ||
Product Version | 1.5.5.svn | ||||
Summary | 0015600: [PATCH] it should not be possible to insert multiple soft hyphens one after the other | ||||
Description | scribus should allow only one soft hyphen at a time. subsequent insertions of soft hyphens should just be ignored. (to be clear: this "brid------ge" should not be possible) | ||||
Tags | No tags attached. | ||||
Patch | Yes | ||||
|
the attached patch removes the unused check for (unicodevalue!=-1) (see the comment in the original code) and makes sure that one does not adds multiple soft hyphens in a row (which can happen, since you don't see where there are already soft hyphens). |
|
dont-duplicate-softhyphen.diff (5,330 bytes)
diff --git a/scribus/scribus.cpp b/scribus/scribus.cpp index 792763a73..46c65fb94 100644 --- a/scribus/scribus.cpp +++ b/scribus/scribus.cpp @@ -1618,75 +1618,41 @@ void ScribusMainWindow::specialActionKeyEvent(int unicodevalue) if (currItem == nullptr) return; - if (unicodevalue!=-1) + if (unicodevalue == SpecialChars::SHYPHEN.unicode() && !canInsertSoftHyphen(currItem)) + return; + + UndoTransaction activeTransaction; + if (currItem->HasSel) { - UndoTransaction activeTransaction; - if (currItem->HasSel) - { - if (UndoManager::undoEnabled()) - activeTransaction = m_undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::ReplaceText, QString(), Um::IDelete); - currItem->deleteSelectedTextFromFrame(); - } if (UndoManager::undoEnabled()) - { - SimpleState *ss = dynamic_cast<SimpleState*>(m_undoManager->getLastUndo()); - UndoObject *undoTarget = currItem; - if (ss && (ss->get("ETEA") == "insert_frametext") && (ss->undoObject() == undoTarget)) - ss->set("TEXT_STR", ss->get("TEXT_STR") + QString(QChar(unicodevalue))); - else - { - ss = new SimpleState(Um::InsertText, QString(), Um::ICreate); - ss->set("INSERT_FRAMETEXT"); - ss->set("ETEA", QString("insert_frametext")); - ss->set("TEXT_STR", QString(QChar(unicodevalue))); - ss->set("START", currItem->itemText.cursorPosition()); - if (currItem->isNoteFrame()) - { - undoTarget = doc; - ss->set("noteframeName", currItem->getUName()); - } - m_undoManager->action(undoTarget, ss); - } - } - currItem->itemText.insertChars(QString(QChar(unicodevalue)), true); - if (activeTransaction) - activeTransaction.commit(); + activeTransaction = m_undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::ReplaceText, QString(), Um::IDelete); + currItem->deleteSelectedTextFromFrame(); } - else if (unicodevalue == SpecialChars::SHYPHEN.unicode()) //ignore the char as we use an attribute if the text item, for now. + if (UndoManager::undoEnabled()) { - // this code is currently dead since unicodeSoftHyphen - // doesn't have unicodevalue == -1 any more - if (currItem->itemText.cursorPosition() <= 1) - return; -#if 0 - StyleFlag fl = currItem->itemText.item(qMax(currItem->CPos-1,0))->effects(); - fl |= ScStyle_HyphenationPossible; - currItem->itemText.item(qMax(currItem->CPos-1,0))->setEffects(fl); -#else - if (UndoManager::undoEnabled()) + SimpleState *ss = dynamic_cast<SimpleState*>(m_undoManager->getLastUndo()); + UndoObject *undoTarget = currItem; + if (ss && (ss->get("ETEA") == "insert_frametext") && (ss->undoObject() == undoTarget)) + ss->set("TEXT_STR", ss->get("TEXT_STR") + QString(QChar(unicodevalue))); + else { - SimpleState *ss = dynamic_cast<SimpleState*>(m_undoManager->getLastUndo()); - UndoObject *undoTarget = currItem; - if (ss && (ss->get("ETEA") == "insert_frametext") && (ss->undoObject() == undoTarget)) - ss->set("TEXT_STR", ss->get("TEXT_STR") + QString(SpecialChars::SHYPHEN)); - else + ss = new SimpleState(Um::InsertText, QString(), Um::ICreate); + ss->set("INSERT_FRAMETEXT"); + ss->set("ETEA", QString("insert_frametext")); + ss->set("TEXT_STR", QString(QChar(unicodevalue))); + ss->set("START", currItem->itemText.cursorPosition()); + if (currItem->isNoteFrame()) { - ss = new SimpleState(Um::InsertText, QString(), Um::ICreate); - ss->set("INSERT_FRAMETEXT"); - ss->set("ETEA", QString("insert_frametext")); - ss->set("TEXT_STR", QString(SpecialChars::SHYPHEN)); - ss->set("START", currItem->itemText.cursorPosition()); - if (currItem->isNoteFrame()) - { - undoTarget = doc; - ss->set("noteframeName", currItem->getUName()); - } - m_undoManager->action(undoTarget, ss); + undoTarget = doc; + ss->set("noteframeName", currItem->getUName()); } + m_undoManager->action(undoTarget, ss); } - currItem->itemText.insertChars(QString(SpecialChars::SHYPHEN), true); -#endif } + currItem->itemText.insertChars(QString(QChar(unicodevalue)), true); + if (activeTransaction) + activeTransaction.commit(); + if (doc->appMode == modeEditTable) selItem->asTable()->update(); else @@ -9330,6 +9296,23 @@ void ScribusMainWindow::updateTableMenuActions() appModeHelper->updateTableMenuActions(doc); } +bool ScribusMainWindow::canInsertSoftHyphen(PageItem_TextFrame* currItem) +{ + int len = currItem->itemText.length(); + if (len == 0) + return true; + + int pos = currItem->itemText.cursorPosition(); + if (pos > 0) + if (currItem->itemText.text(pos - 1) == SpecialChars::SHYPHEN) + return false; + if (pos < len) + if (currItem->itemText.text(pos) == SpecialChars::SHYPHEN) + return false; + + return true; +} + void ScribusMainWindow::insertMark(MarkType mType) { if (!HaveDoc) diff --git a/scribus/scribus.h b/scribus/scribus.h index 91fc4c7df..e6031b2d3 100644 --- a/scribus/scribus.h +++ b/scribus/scribus.h @@ -667,6 +667,9 @@ private: QPointer<HelpBrowser> m_helpBrowser; QString m_osgFilterString; + /** False if the character before or after the insertion point is already a soft hyphen */ + bool canInsertSoftHyphen(PageItem_TextFrame* currItem); + void insertMark(MarkType); bool insertMarkDialog(PageItem_TextFrame* item, MarkType mT, ScItemsState* &is); int m_marksCount; //remember marks count from last call |
|
here is a new much simpler patch (which basically does the same thing...) p.s.: when applying this patch, please add a comment at top, something like: // avoid consecutive soft hyphens single-soft-hyphen.diff (648 bytes)
diff --git a/scribus/scribus.cpp b/scribus/scribus.cpp index bf92a7a1d..4ffd9864e 100644 --- a/scribus/scribus.cpp +++ b/scribus/scribus.cpp @@ -1661,6 +1661,14 @@ void ScribusMainWindow::specialActionKeyEvent(int unicodevalue) currItem = selItem->asTextFrame(); if (currItem == nullptr) return; + if (unicodevalue == SpecialChars::SHYPHEN.unicode()) + { + auto pos = currItem->itemText.cursorPosition(); + if (pos > 0 && currItem->itemText.text(pos - 1) == SpecialChars::SHYPHEN) + return; + if (pos < currItem->itemText.length() && currItem->itemText.text(pos) == SpecialChars::SHYPHEN) + return; + } if (unicodevalue!=-1) { |
|
any comment? |
Date Modified | Username | Field | Change |
---|---|---|---|
2019-03-13 16:12 | ale | New Issue | |
2020-10-26 19:16 | ale | Note Added: 0048214 | |
2020-10-26 19:17 | ale | File Added: dont-duplicate-softhyphen.diff | |
2020-10-26 19:17 | ale | Summary | it should not be possible to insert multiple soft hyphens one after the other => [PATCH] it should not be possible to insert multiple soft hyphens one after the other |
2020-10-26 19:17 | ale | Patch | No => Yes |
2024-03-16 14:20 | ale | Note Added: 0051046 | |
2024-03-16 14:20 | ale | File Added: single-soft-hyphen.diff | |
2024-03-16 18:32 | ale | Note Edited: 0051046 | |
2024-06-17 14:47 | ale | Note Added: 0051221 |