{
int y, x;
unichar ch;
- int addedSpaces, addedTabs;
+ int addedSpaces, addedTabs, xAdjustment;
type = class(AddCharAction);
void Undo(EditBox editBox)
{
- editBox.GoToPosition(null, (ch == '\n') ? (y + 1) : y, (ch == '\n') ? 0 : (x + 1));
+ editBox.GoToPosition(null, (ch == '\n') ? (y + 1) : y, (ch == '\n') ? 0 : (x + 1) - xAdjustment);
editBox.BackSpace();
if(addedTabs || addedSpaces)
- editBox.DelCh(editBox.line, y, x - (addedSpaces + addedTabs), editBox.line, y, x, false);
+ {
+ editBox.DelCh(editBox.line, y, x - xAdjustment - (addedSpaces + addedTabs), editBox.line, y, x - xAdjustment, false);
+ editBox.GoToPosition(editBox.line, y, x);
+ }
editBox.UpdateDirty();
}
{
int y1, x1, y2, x2;
char * string;
- int addedSpaces, addedTabs;
+ int addedSpaces, addedTabs, xAdjustment;
type = class(AddTextAction);
#ifdef _DEBUG
char * oldString;
char * newString;
bool placeAfter;
- int addedSpaces, addedTabs;
+ int addedSpaces, addedTabs, xAdjustment;
type = class(ReplaceTextAction);
return false;
}
- bool AddToLine(const char * stringLine, int count, bool LFComing, int * addedSpacesPtr, int * addedTabsPtr)
+ bool AddToLine(const char * stringLine, int count, bool LFComing, int * addedSpacesPtr, int * addedTabsPtr, int * xAdjustmentPtr)
{
bool hadComment = false;
// Add the line here
{
int addedSpaces = 0;
int addedTabs = 0;
+ int xAdjustment = 0;
// Add blank spaces if EES_FREECARET
if(this.x > line.count)
addedSpaces = wantedPosition - position;
else
{
+ xAdjustment = wantedPosition - position;
+
// Put a first tab
addedTabs = 1;
position += this.tabSize - (position % this.tabSize);
position += (addedTabs-1) * this.tabSize;
// Finish off with spaces
addedSpaces = wantedPosition - position;
+
+ xAdjustment -= addedSpaces + addedTabs;
}
}
else
CopyBytes(line.buffer + this.x + addedTabs + addedSpaces, stringLine, count);
if(addedTabs)
{
- *addedTabsPtr = addedTabs;
FillBytes(line.buffer+line.count,'\t',addedTabs);
#ifdef _DEBUG
if(addedTabs > 4000 || addedTabs < 0)
#endif
line.count += addedTabs;
}
- else if(addedTabs)
- *addedTabsPtr = 0;
+
if(addedSpaces)
{
FillBytes(line.buffer+line.count,' ',addedSpaces);
printf("Warning");
#endif
line.count += addedSpaces;
- if(addedSpacesPtr) *addedSpacesPtr = addedSpaces;
}
- else if(addedSpacesPtr)
- *addedSpacesPtr = 0;
+
+ if(addedTabsPtr) *addedTabsPtr = addedTabs;
+ if(addedSpacesPtr) *addedSpacesPtr = addedSpaces;
+ if(xAdjustmentPtr) *xAdjustmentPtr = xAdjustment;
#ifdef _DEBUG
if(count > 4000 || count < 0)
printf("Warning");
UpdateDirty();
}
- bool _AddCh(unichar ch, int * addedSpacesPtr, int * addedTabsPtr)
+ bool _AddCh(unichar ch, int * addedSpacesPtr, int * addedTabsPtr, int * xAdjustmentPtr)
{
EditLine line;
int length, endX = 0;
bool result;
ReplaceTextAction replaceAction = null;
AddCharAction addCharAction = null;
- int addedSpaces = 0, addedTabs = 0;
+ int addedSpaces = 0, addedTabs = 0, xAdjustment = 0;
if(ch == '\r') return true;
if(style.stuckCaret /*|EES_READONLY)*/ )
char string[5];
int count = UTF32toUTF8Len(&ch, 1, string, 5);
DelSel(&addedSpaces);
- result = AddToLine(string, count, false, addedSpaces ? null : &addedSpaces, &addedTabs);
+ result = AddToLine(string, count, false, addedSpaces ? null : &addedSpaces, &addedTabs, &xAdjustment);
if(addedSpacesPtr) *addedSpacesPtr = addedSpaces;
if(addedTabsPtr) *addedTabsPtr = addedTabs;
+ if(xAdjustmentPtr) *xAdjustmentPtr = xAdjustment;
}
this.selX = this.x;
this.selY = this.y;
bool AddCh(unichar ch)
{
- return _AddCh(ch, null, null);
+ return _AddCh(ch, null, null, null);
}
void Modified()
bool ret = true;
const char * line;
int c, count;
- int addedSpaces = 0, addedTabs = 0;
+ int addedSpaces = 0, addedTabs = 0, xAdjustment = 0;
AddTextAction action = null;
ReplaceTextAction replaceAction = null;
{
if(string[c] == '\n' || string[c] == '\r')
{
- if(!AddToLine(line, count, true, addedSpaces ? null : &addedSpaces, addedTabs ? null : &addedTabs))
+ if(!AddToLine(line, count, true, addedSpaces ? null : &addedSpaces, addedTabs ? null : &addedTabs, xAdjustment ? null : &xAdjustment))
{
ret = false;
break;
// Add the line here
if(ret && count)
- if(!AddToLine(line,count,false, addedSpaces ? null : &addedSpaces, addedTabs ? null : &addedTabs))
+ if(!AddToLine(line,count,false, addedSpaces ? null : &addedSpaces, addedTabs ? null : &addedTabs, xAdjustment ? null : &xAdjustment))
{
ret = false;
}
action.x2 = x;
action.addedSpaces = addedSpaces;
action.addedTabs = addedTabs;
+ action.xAdjustment = xAdjustment;
}
else if(replaceAction)
{
replaceAction.x3 = x;
replaceAction.addedSpaces = addedSpaces;
replaceAction.addedTabs = addedTabs;
+ replaceAction.xAdjustment = xAdjustment;
}
UpdateCaretPosition(true);
if((ch >= 32 /*&& ch <=126*/) || ch == '\n')
//if((ch >= 32) || ch == '\n')
{
- int addedSpaces = 0, addedTabs = 0;
+ int addedSpaces = 0, addedTabs = 0, xAdjustment = 0;
ReplaceTextAction replaceAction = null;
AddCharAction addCharAction = null;
}
}
undoBuffer.dontRecord++;
- result = _AddCh(ch, &addedSpaces, &addedTabs);
+ result = _AddCh(ch, &addedSpaces, &addedTabs, &xAdjustment);
if(replaceAction)
{
replaceAction.x3 = x;
replaceAction.y3 = y;
replaceAction.addedSpaces = addedSpaces;
replaceAction.addedTabs = addedTabs;
+ replaceAction.addedTabs = xAdjustment;
}
if(addCharAction)
{
- addCharAction.x -= addedTabs * (tabSize-1);
addCharAction.addedSpaces = addedSpaces;
addCharAction.addedTabs = addedTabs;
+ addCharAction.xAdjustment = xAdjustment;
}
undoBuffer.dontRecord--;
if(ch == '\n')