Skip to content

Commit

Permalink
updated Scintilla to version 1.67
Browse files Browse the repository at this point in the history
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@135 ea778897-0a13-0410-b9d1-a72fbfd435f5
  • Loading branch information
eht16 committed Jan 16, 2006
1 parent 18b1d12 commit 45c8bed
Show file tree
Hide file tree
Showing 18 changed files with 450 additions and 248 deletions.
25 changes: 10 additions & 15 deletions scintilla/CellBuffer.cxx
Expand Up @@ -465,15 +465,15 @@ void UndoHistory::AppendAction(actionType at, int position, char *data, int leng
} else if (currentAction == savePoint) {
currentAction++;
} else if ((at == insertAction) &&
(position != (actPrevious.position + actPrevious.lenData*2))) {
(position != (actPrevious.position + actPrevious.lenData))) {
// Insertions must be immediately after to coalesce
currentAction++;
} else if (!actions[currentAction].mayCoalesce) {
// Not allowed to coalesce if this set
currentAction++;
} else if (at == removeAction) {
if ((lengthData == 1) || (lengthData == 2)){
if ((position + lengthData * 2) == actPrevious.position) {
if ((position + lengthData) == actPrevious.position) {
; // Backspace -> OK
} else if (position == actPrevious.position) {
; // Delete -> OK
Expand Down Expand Up @@ -725,21 +725,14 @@ const char *CellBuffer::InsertString(int position, char *s, int insertLength) {
for (int i = 0; i < insertLength / 2; i++) {
data[i] = s[i * 2];
}
uh.AppendAction(insertAction, position, data, insertLength / 2);
uh.AppendAction(insertAction, position / 2, data, insertLength / 2);
}

BasicInsertString(position, s, insertLength);
}
return data;
}

void CellBuffer::InsertCharStyle(int position, char ch, char style) {
char s[2];
s[0] = ch;
s[1] = style;
InsertString(position*2, s, 2);
}

bool CellBuffer::SetStyleAt(int position, char style, char mask) {
style &= mask;
char curVal = ByteAt(position * 2 + 1);
Expand Down Expand Up @@ -769,6 +762,7 @@ bool CellBuffer::SetStyleFor(int position, int lengthStyle, char style, char mas

const char *CellBuffer::DeleteChars(int position, int deleteLength) {
// InsertString and DeleteChars are the bottleneck though which all changes occur
PLATFORM_ASSERT(deleteLength > 0);
char *data = 0;
if (!readOnly) {
if (collectingUndo) {
Expand All @@ -777,7 +771,7 @@ const char *CellBuffer::DeleteChars(int position, int deleteLength) {
for (int i = 0; i < deleteLength / 2; i++) {
data[i] = ByteAt(position + i * 2);
}
uh.AppendAction(removeAction, position, data, deleteLength / 2);
uh.AppendAction(removeAction, position / 2, data, deleteLength / 2);
}

BasicDeleteChars(position, deleteLength);
Expand Down Expand Up @@ -875,6 +869,7 @@ void CellBuffer::BasicInsertString(int position, char *s, int insertLength) {
//Platform::DebugPrintf("Inserting at %d for %d\n", position, insertLength);
if (insertLength == 0)
return ;
PLATFORM_ASSERT(insertLength > 0);
RoomFor(insertLength);
GapTo(position);

Expand Down Expand Up @@ -1043,14 +1038,14 @@ const Action &CellBuffer::GetUndoStep() const {
void CellBuffer::PerformUndoStep() {
const Action &actionStep = uh.GetUndoStep();
if (actionStep.at == insertAction) {
BasicDeleteChars(actionStep.position, actionStep.lenData*2);
BasicDeleteChars(actionStep.position*2, actionStep.lenData*2);
} else if (actionStep.at == removeAction) {
char *styledData = new char[actionStep.lenData * 2];
for (int i = 0; i < actionStep.lenData; i++) {
styledData[i*2] = actionStep.data[i];
styledData[i*2 + 1] = 0;
}
BasicInsertString(actionStep.position, styledData, actionStep.lenData*2);
BasicInsertString(actionStep.position*2, styledData, actionStep.lenData*2);
delete []styledData;
}
uh.CompletedUndoStep();
Expand All @@ -1076,10 +1071,10 @@ void CellBuffer::PerformRedoStep() {
styledData[i*2] = actionStep.data[i];
styledData[i*2 + 1] = 0;
}
BasicInsertString(actionStep.position, styledData, actionStep.lenData*2);
BasicInsertString(actionStep.position*2, styledData, actionStep.lenData*2);
delete []styledData;
} else if (actionStep.at == removeAction) {
BasicDeleteChars(actionStep.position, actionStep.lenData*2);
BasicDeleteChars(actionStep.position*2, actionStep.lenData*2);
}
uh.CompletedRedoStep();
}
Expand Down
1 change: 0 additions & 1 deletion scintilla/CellBuffer.h
Expand Up @@ -191,7 +191,6 @@ class CellBuffer {
int LineStart(int line);
int LineFromPosition(int pos) { return lv.LineFromPosition(pos); }
const char *InsertString(int position, char *s, int insertLength);
void InsertCharStyle(int position, char ch, char style);

/// Setting styles for positions outside the range of the buffer is safe and has no effect.
/// @return true if the style of a character is changed.
Expand Down
94 changes: 83 additions & 11 deletions scintilla/Document.cxx
Expand Up @@ -104,25 +104,39 @@ void Document::SetSavePoint() {
int Document::AddMark(int line, int markerNum) {
int prev = cb.AddMark(line, markerNum);
DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line);
mh.line = line;
NotifyModified(mh);
return prev;
}

void Document::AddMarkSet(int line, int valueSet) {
unsigned int m = valueSet;
for (int i = 0; m; i++, m >>= 1)
if (m & 1)
cb.AddMark(line, i);
DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line);
mh.line = line;
NotifyModified(mh);
}

void Document::DeleteMark(int line, int markerNum) {
cb.DeleteMark(line, markerNum);
DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line);
mh.line = line;
NotifyModified(mh);
}

void Document::DeleteMarkFromHandle(int markerHandle) {
cb.DeleteMarkFromHandle(markerHandle);
DocModification mh(SC_MOD_CHANGEMARKER, 0, 0, 0, 0);
mh.line = -1;
NotifyModified(mh);
}

void Document::DeleteAllMarks(int markerNum) {
cb.DeleteAllMarks(markerNum);
DocModification mh(SC_MOD_CHANGEMARKER, 0, 0, 0, 0);
mh.line = -1;
NotifyModified(mh);
}

Expand Down Expand Up @@ -437,7 +451,7 @@ int Document::Undo() {
SC_MOD_BEFOREDELETE | SC_PERFORMED_UNDO, action));
}
cb.PerformUndoStep();
int cellPosition = action.position / 2;
int cellPosition = action.position;
ModifiedAt(cellPosition);
newPos = cellPosition;

Expand Down Expand Up @@ -492,8 +506,8 @@ int Document::Redo() {
SC_MOD_BEFOREDELETE | SC_PERFORMED_REDO, action));
}
cb.PerformRedoStep();
ModifiedAt(action.position / 2);
newPos = action.position / 2;
ModifiedAt(action.position);
newPos = action.position;

int modFlags = SC_PERFORMED_REDO;
if (action.at == insertAction) {
Expand All @@ -513,7 +527,7 @@ int Document::Redo() {
modFlags |= SC_MULTILINEUNDOREDO;
}
NotifyModified(
DocModification(modFlags, action.position / 2, action.lenData,
DocModification(modFlags, action.position, action.lenData,
linesAdded, action.data));
}

Expand Down Expand Up @@ -703,10 +717,13 @@ void Document::Indent(bool forwards, int lineBottom, int lineTop) {
// Dedent - suck white space off the front of the line to dedent by equivalent of a tab
for (int line = lineBottom; line >= lineTop; line--) {
int indentOfLine = GetLineIndentation(line);
if (forwards)
SetLineIndentation(line, indentOfLine + IndentSize());
else
if (forwards) {
if (LineStart(line) < LineEnd(line)) {
SetLineIndentation(line, indentOfLine + IndentSize());
}
} else {
SetLineIndentation(line, indentOfLine - IndentSize());
}
}
}

Expand Down Expand Up @@ -1309,19 +1326,22 @@ bool Document::SetStyles(int length, char *styles) {
return false;
} else {
enteredCount++;
int prevEndStyled = endStyled;
bool didChange = false;
int lastChange = 0;
int startMod = 0;
int endMod = 0;
for (int iPos = 0; iPos < length; iPos++, endStyled++) {
PLATFORM_ASSERT(endStyled < Length());
if (cb.SetStyleAt(endStyled, styles[iPos], stylingMask)) {
if (!didChange) {
startMod = endStyled;
}
didChange = true;
lastChange = iPos;
endMod = endStyled;
}
}
if (didChange) {
DocModification mh(SC_MOD_CHANGESTYLE | SC_PERFORMED_USER,
prevEndStyled, lastChange);
startMod, endMod - startMod + 1);
NotifyModified(mh);
}
enteredCount--;
Expand Down Expand Up @@ -1519,3 +1539,55 @@ int Document::ExtendStyleRange(int pos, int delta, bool singleLine) {
}
return pos;
}

static char BraceOpposite(char ch) {
switch (ch) {
case '(':
return ')';
case ')':
return '(';
case '[':
return ']';
case ']':
return '[';
case '{':
return '}';
case '}':
return '{';
case '<':
return '>';
case '>':
return '<';
default:
return '\0';
}
}

// TODO: should be able to extend styled region to find matching brace
int Document::BraceMatch(int position, int /*maxReStyle*/) {
char chBrace = CharAt(position);
char chSeek = BraceOpposite(chBrace);
if (chSeek == '\0')
return - 1;
char styBrace = static_cast<char>(StyleAt(position) & stylingBitsMask);
int direction = -1;
if (chBrace == '(' || chBrace == '[' || chBrace == '{' || chBrace == '<')
direction = 1;
int depth = 1;
position = position + direction;
while ((position >= 0) && (position < Length())) {
position = MovePositionOutsideChar(position, direction);
char chAtPos = CharAt(position);
char styAtPos = static_cast<char>(StyleAt(position) & stylingBitsMask);
if ((position > GetEndStyled()) || (styAtPos == styBrace)) {
if (chAtPos == chBrace)
depth++;
if (chAtPos == chSeek)
depth--;
if (depth == 0)
return position;
}
position = position + direction;
}
return - 1;
}
4 changes: 3 additions & 1 deletion scintilla/Document.h
Expand Up @@ -176,6 +176,7 @@ class Document {
char StyleAt(int position) { return cb.StyleAt(position); }
int GetMark(int line) { return cb.GetMark(line); }
int AddMark(int line, int markerNum);
void AddMarkSet(int line, int valueSet);
void DeleteMark(int line, int markerNum);
void DeleteMarkFromHandle(int markerHandle);
void DeleteAllMarks(int markerNum);
Expand Down Expand Up @@ -233,6 +234,7 @@ class Document {
int ParaUp(int pos);
int ParaDown(int pos);
int IndentSize() { return actualIndentInChars; }
int BraceMatch(int position, int maxReStyle);

private:
void CheckReadOnly();
Expand Down Expand Up @@ -276,7 +278,7 @@ class DocModification {

DocModification(int modificationType_, const Action &act, int linesAdded_=0) :
modificationType(modificationType_),
position(act.position / 2),
position(act.position),
length(act.lenData),
linesAdded(linesAdded_),
text(act.data),
Expand Down

0 comments on commit 45c8bed

Please sign in to comment.