r16462 by jghali - #9838: Crash when changing any text setting after entering some new text in a new frame
scribus-commit
scribus-commit at lists.scribus.net
Sun Mar 20 00:15:22 CET 2011
Author: jghali
Date: Sat Mar 19 23:15:21 2011
New Revision: 16462
URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=16462
Log:
#9838: Crash when changing any text setting after entering some new text in a new frame
Modified:
branches/Version135/Scribus/scribus/pageitem.cpp
branches/Version135/Scribus/scribus/pageitem_textframe.cpp
branches/Version135/Scribus/scribus/pageitem_textframe.h
Modified: branches/Version135/Scribus/scribus/pageitem.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16462&path=/branches/Version135/Scribus/scribus/pageitem.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem.cpp (original)
+++ branches/Version135/Scribus/scribus/pageitem.cpp Sat Mar 19 23:15:21 2011
@@ -3796,6 +3796,8 @@
{
if (!isTextFrame())
return;
+ itemText.deselectAll();
+ HasSel = false;
EditAct action = (EditAct) state->getInt("STEXT");
if (action == PARAMFULL || action == PARAMSEL)
{
@@ -3821,10 +3823,11 @@
else if (action == PARAMSEL)
{
itemText.deselectAll();
- itemText.select(state->getInt("STEXT_SELSTART"),state->getInt("STEXT_SELLEN"));
+ int SelStart = state->getInt("STEXT_SELSTART");
+ itemText.select(SelStart,state->getInt("STEXT_SELLEN"));
asTextFrame()->deleteSelectedTextFromFrame();
- itemText.insert(state->getInt("STEXT_SELSTART"), *story);
- itemText.select(state->getInt("STEXT_SELSTART"), story->length());
+ itemText.insert(SelStart, *story);
+ itemText.select(SelStart, story->length());
HasSel = true;
}
CPos = itemText.endOfSelection();
@@ -3853,7 +3856,7 @@
dig.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>());
dig.parseMemory(buffout.toStdString().c_str(), buffout.length());
StoryText* story = dig.result<StoryText>();
- itemText.select(pos,story->length(), true);
+ itemText.select(pos,story->length());
asTextFrame()->deleteSelectedTextFromFrame();
Serializer dig2(*m_Doc);
@@ -3941,6 +3944,8 @@
LenOldSel = itemText.lengthOfSelection();
if (LenOldSel > 0)
StartOldSel = itemText.startOfSelection();
+ if (CPos >= itemText.length())
+ return "";
itemText.select(CPos,1);
HasSel = true;
}
Modified: branches/Version135/Scribus/scribus/pageitem_textframe.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16462&path=/branches/Version135/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem_textframe.cpp (original)
+++ branches/Version135/Scribus/scribus/pageitem_textframe.cpp Sat Mar 19 23:15:21 2011
@@ -3640,6 +3640,24 @@
{
if (UndoManager::undoEnabled() && undoManager->undoEnabled())
{
+ int oldSelStart = -1, oldSelLen = -1;
+ oldSelLen = itemText.lengthOfSelection();
+ if (oldSelLen > 0)
+ oldSelStart = itemText.startOfSelection();
+ if (action == PARAMFULL && m_Doc->appMode == modeEdit)
+ {
+ //action is for paragraph where cursor is
+ ExpandParSel();
+ action = PARAMSEL;
+ }
+ if (CPos >= itemText.length() && itemTextSaxed.isEmpty() && action == PARAMFULL && m_Doc->appMode == modeEdit)
+ {
+ //case when cursor is after last character without selection and nothing was and will be done
+ //changes will be ignored
+ lastUndoAction = PageItem::NOACTION;
+ restoreTextSelection(oldSelStart, oldSelLen);
+ return;
+ }
SimpleState* ss;
bool newState = true; // indicate when new undoState should be created
if (lastUndoAction == action && action != REPSAX && action != DELSAX)
@@ -3664,7 +3682,7 @@
if (newState)
{
ss = new SimpleState(UndoManager::EditText);
- ss->set("STEXT_CPOS",oldCPos);
+ ss->set("STEXT_CPOS", oldCPos);
}
if (action == INSSAX || action == INS)
ss->set("STEXT_STR",str);
@@ -3677,10 +3695,6 @@
}
else
{
- int oldSelStart = -1, oldSelLen = -1;
- oldSelLen = itemText.lengthOfSelection();
- if (oldSelLen > 0)
- oldSelStart = itemText.startOfSelection();
if (action == PARAMFULL && m_Doc->appMode == modeEdit)
{
//action is for paragraph where cursor is
@@ -3691,25 +3705,16 @@
{
ss->set("STEXT_CPOS",CPos);
ss->set("STEXT_SELSTART", itemText.startOfSelection());
- ss->set("STEXT_SELLEN", itemText.endOfSelection() - itemText.startOfSelection());
+ ss->set("STEXT_SELLEN", itemText.lengthOfSelection());
}
ss->set("STEXT_OLD", itemTextSaxed);
itemTextSaxed = getItemTextSaxed((action == PARAMSEL) ? SELECTION : FRAME);
ss->set("STEXT_NEW", itemTextSaxed);
- if (oldSelLen > 0)
- {
- itemText.select(oldSelStart, oldSelLen);
- HasSel = true;
- }
- else if (oldSelLen == 0)
- {
- itemText.deselectAll();
- HasSel = false;
- }
if (QString::compare(ss->get("STEXT_OLD"),ss->get("STEXT_NEW")) == 0)
{
//nothing change - quit without set new Undo step
itemTextSaxed.clear();
+ restoreTextSelection(oldSelStart, oldSelLen);
delete ss;
return;
}
@@ -3719,5 +3724,16 @@
ss->set("STEXT",(int) action);
if (newState)
undoManager->action(this, ss);
+ // Restore user selection
+ restoreTextSelection(oldSelStart, oldSelLen);
}
}
+
+void PageItem_TextFrame::restoreTextSelection(int oldSelStart, int oldSelLength)
+{
+ if (oldSelLength > 0)
+ itemText.select(oldSelStart, oldSelLength);
+ else if (oldSelLength == 0)
+ itemText.deselectAll();
+ HasSel = (oldSelLength > 0);
+}
Modified: branches/Version135/Scribus/scribus/pageitem_textframe.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16462&path=/branches/Version135/Scribus/scribus/pageitem_textframe.h
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem_textframe.h (original)
+++ branches/Version135/Scribus/scribus/pageitem_textframe.h Sat Mar 19 23:15:21 2011
@@ -103,6 +103,7 @@
bool cursorBiasBackward;
void setShadow();
+ void restoreTextSelection(int selStart, int selLength);
QString currentShadow;
QMap<QString,StoryText> shadows;
public:
More information about the scribus-commit
mailing list