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