diff options
| author | nyamatongwe <devnull@localhost> | 2000-09-06 04:39:54 +0000 | 
|---|---|---|
| committer | nyamatongwe <devnull@localhost> | 2000-09-06 04:39:54 +0000 | 
| commit | 924a6fc31c118e722d4b1eba494c1675d0b2810c (patch) | |
| tree | e17396085bcef0ba8159369320d1c93d06c8aaf1 /src | |
| parent | 7896d9a43bcf6a9a8a627dc542743ff1b41bd911 (diff) | |
| download | scintilla-mirror-924a6fc31c118e722d4b1eba494c1675d0b2810c.tar.gz | |
Fix from Tahir Karaca for LineVector::MergeMarkers.
Diffstat (limited to 'src')
| -rw-r--r-- | src/CellBuffer.cxx | 123 | 
1 files changed, 65 insertions, 58 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 68bcde2ed..befec75fc 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -88,7 +88,7 @@ void MarkerHandleSet::RemoveHandle(int handle) {  		if (mhn->handle == handle) {  			*pmhn = mhn->next;  			delete mhn; -			return; +			return ;  		}  		pmhn = &((*pmhn)->next);  	} @@ -101,7 +101,7 @@ void MarkerHandleSet::RemoveNumber(int markerNum) {  		if (mhn->number == markerNum) {  			*pmhn = mhn->next;  			delete mhn; -			return; +			return ;  		}  		pmhn = &((*pmhn)->next);  	} @@ -119,9 +119,9 @@ void MarkerHandleSet::CombineWith(MarkerHandleSet *other) {  LineVector::LineVector() {  	linesData = 0;  	lines = 0; -    size = 0; +	size = 0;  	levels = 0; -    sizeLevels = 0; +	sizeLevels = 0;  	handleCurrent = 1;  	Init(); @@ -165,6 +165,7 @@ void LineVector::Expand(int sizeNew) {  		Platform::DebugPrintf("No memory available\n");  		// TODO: Blow up  	} +  }  void LineVector::ExpandLevels(int sizeNew) { @@ -184,12 +185,13 @@ void LineVector::ExpandLevels(int sizeNew) {  		Platform::DebugPrintf("No memory available\n");  		// TODO: Blow up  	} +  }  void LineVector::ClearLevels() {  	delete []levels;  	levels = 0; -    sizeLevels = 0; +	sizeLevels = 0;  }  void LineVector::InsertValue(int pos, int value) { @@ -212,10 +214,10 @@ void LineVector::InsertValue(int pos, int value) {  		}  		if (pos == 0) {  			levels[pos] = SC_FOLDLEVELBASE; -		} else if (pos == (lines-1)) {	// Last line will not be a folder +		} else if (pos == (lines - 1)) {	// Last line will not be a folder  			levels[pos] = SC_FOLDLEVELBASE;  		} else { -			levels[pos] = levels[pos-1]; +			levels[pos] = levels[pos - 1];  		}  	}  } @@ -244,10 +246,10 @@ void LineVector::Remove(int pos) {  		linesData[i] = linesData[i + 1];  	}  	if (levels) { -        // Level information merges back onto previous line -        int posAbove = pos-1; -        if (posAbove < 0) -            posAbove = 0; +		// Level information merges back onto previous line +		int posAbove = pos - 1; +		if (posAbove < 0) +			posAbove = 0;  		for (int j = posAbove; j < lines; j++) {  			levels[j] = levels[j + 1];  		} @@ -290,11 +292,12 @@ int LineVector::AddMark(int line, int markerNum) {  }  void LineVector::MergeMarkers(int pos) { -	if (linesData[pos].handleSet || linesData[pos + 1].handleSet) { -		if (linesData[pos].handleSet && linesData[pos + 1].handleSet) { -			linesData[pos].handleSet->CombineWith(linesData[pos].handleSet); -			linesData[pos].handleSet = 0; -		} +	if (linesData[pos + 1].handleSet != NULL) { +		if (linesData[pos].handleSet == NULL ) +			linesData[pos].handleSet = new MarkerHandleSet; +		linesData[pos].handleSet->CombineWith(linesData[pos + 1].handleSet); +		delete linesData[pos + 1].handleSet; +		linesData[pos + 1].handleSet = NULL;  	}  } @@ -368,7 +371,7 @@ void Action::Grab(Action *source) {  	data = source->data;  	lenData = source->lenData;  	mayCoalesce = source->mayCoalesce; -	 +  	// Ownership of source data transferred to this  	source->position = 0;  	source->at = startAction; @@ -377,21 +380,21 @@ void Action::Grab(Action *source) {  	source->mayCoalesce = true;  } -// The undo history stores a sequence of user operations that represent the user's view of the  -// commands executed on the text.  +// The undo history stores a sequence of user operations that represent the user's view of the +// commands executed on the text.  // Each user operation contains a sequence of text insertion and text deletion actions.  // All the user operations are stored in a list of individual actions with 'start' actions used  // as delimiters between user operations. -// Initially there is one start action in the history.  -// As each action is performed, it is recorded in the history. The action may either become  +// Initially there is one start action in the history. +// As each action is performed, it is recorded in the history. The action may either become  // part of the current user operation or may start a new user operation. If it is to be part of the -// current operation, then it overwrites the current last action. If it is to be part of a new  +// current operation, then it overwrites the current last action. If it is to be part of a new  // operation, it is appended after the current last action.  // After writing the new action, a new start action is appended at the end of the history. -// The decision of whether to start a new user operation is based upon two factors. If a  +// The decision of whether to start a new user operation is based upon two factors. If a  // compound operation has been explicitly started by calling BeginUndoAction and no matching -// EndUndoAction (these calls nest) has been called, then the action is coalesced into the current  -// operation. If there is no outstanding BeginUndoAction call then a new operation is started  +// EndUndoAction (these calls nest) has been called, then the action is coalesced into the current +// operation. If there is no outstanding BeginUndoAction call then a new operation is started  // unless it looks as if the new action is caused by the user typing or deleting a stream of text.  // Sequences that look like typing or deletion are coalesced into a single user operation. @@ -422,7 +425,7 @@ void UndoHistory::EnsureUndoRoom() {  			int lenActionsNew = lenActions * 2;  			Action *actionsNew = new Action[lenActionsNew];  			if (!actionsNew) -				return; +				return ;  			for (int act = 0; act <= currentAction; act++)  				actionsNew[act].Grab(&actions[act]);  			delete []actions; @@ -435,11 +438,11 @@ void UndoHistory::EnsureUndoRoom() {  void UndoHistory::AppendAction(actionType at, int position, char *data, int lengthData) {  	EnsureUndoRoom();  	//Platform::DebugPrintf("%% %d action %d %d %d\n", at, position, lengthData, currentAction); -	//Platform::DebugPrintf("^ %d action %d %d\n", actions[currentAction - 1].at,  +	//Platform::DebugPrintf("^ %d action %d %d\n", actions[currentAction - 1].at,  	//	actions[currentAction - 1].position, actions[currentAction - 1].lenData);  	if (currentAction >= 1) {  		if (0 == undoSequenceDepth) { -		// Top level actions may not always be coalesced +			// Top level actions may not always be coalesced  			Action &actPrevious = actions[currentAction - 1];  			// See if current action can be coalesced into previous action  			// Will work if both are inserts or deletes and position is same @@ -447,22 +450,23 @@ void UndoHistory::AppendAction(actionType at, int position, char *data, int leng  				currentAction++;  			} else if (currentAction == savePoint) {  				currentAction++; -			} else if ((at == removeAction) &&  -				((position + lengthData * 2) != actPrevious.position)) { +			} else if ((at == removeAction) && +			           ((position + lengthData * 2) != actPrevious.position)) {  				// Removals must be at same position to coalesce  				currentAction++; -			} else if ((at == insertAction) &&  -				(position != (actPrevious.position + actPrevious.lenData*2))) { +			} else if ((at == insertAction) && +			           (position != (actPrevious.position + actPrevious.lenData*2))) {  				// Insertions must be immediately after to coalesce  				currentAction++;  			} else {  				//Platform::DebugPrintf("action coalesced\n");  			} +  		} else {  			// Actions not at top level are always coalesced unless this is after return to top level  			if (!actions[currentAction].mayCoalesce)  				currentAction++; -		}  +		}  	} else {  		currentAction++;  	} @@ -497,7 +501,7 @@ void UndoHistory::EndUndoAction() {  		actions[currentAction].mayCoalesce = false;  	}  } -	 +  void UndoHistory::DropUndoSequence() {  	undoSequenceDepth = 0;  } @@ -527,9 +531,9 @@ int UndoHistory::StartUndo() {  	// Drop any trailing startAction  	if (actions[currentAction].at == startAction && currentAction > 0)  		currentAction--; -	 +  	// Count the steps in this action -	int act = currentAction;  +	int act = currentAction;  	while (actions[act].at != startAction && act > 0) {  		act--;  	} @@ -552,9 +556,9 @@ int UndoHistory::StartRedo() {  	// Drop any leading startAction  	if (actions[currentAction].at == startAction && currentAction < maxAction)  		currentAction++; -	 +  	// Count the steps in this action -	int act = currentAction;  +	int act = currentAction;  	while (actions[act].at != startAction && act < maxAction) {  		act++;  	} @@ -573,7 +577,7 @@ CellBuffer::CellBuffer(int initialLength) {  	body = new char[initialLength];  	size = initialLength;  	length = 0; -	part1len = 0;    +	part1len = 0;  	gaplen = initialLength;  	part2body = body + gaplen;  	readOnly = false; @@ -587,7 +591,7 @@ CellBuffer::~CellBuffer() {  void CellBuffer::GapTo(int position) {  	if (position == part1len) -		return; +		return ;  	if (position < part1len) {  		int diff = part1len - position;  		//Platform::DebugPrintf("Move gap backwards to %d diff = %d part1len=%d length=%d \n", position,diff, part1len, length); @@ -619,6 +623,7 @@ void CellBuffer::RoomFor(int insertionLength) {  		size = newSize;  		//Platform::DebugPrintf("end need room %d %d - size=%d length=%d\n", gaplen, insertionLength,size,length);  	} +  }  // To make it easier to write code that uses ByteAt, a position outside the range of the buffer @@ -643,16 +648,16 @@ void CellBuffer::SetByteAt(int position, char ch) {  	if (position < 0) {  		//Platform::DebugPrintf("Bad position %d\n",position); -		return; +		return ;  	}  	if (position >= length + 11) {  		Platform::DebugPrintf("Very Bad position %d of %d\n", position, length);  		//exit(2); -		return; +		return ;  	}  	if (position >= length) {  		//Platform::DebugPrintf("Bad position %d of %d\n",position,length); -		return; +		return ;  	}  	if (position < part1len) { @@ -668,20 +673,20 @@ char CellBuffer::CharAt(int position) {  void CellBuffer::GetCharRange(char *buffer, int position, int lengthRetrieve) {  	if (lengthRetrieve < 0) -		return; +		return ;  	if (position < 0) -		return; +		return ;  	int bytePos = position * 2;  	if ((bytePos + lengthRetrieve * 2) > length) { -		Platform::DebugPrintf("Bad GetCharRange %d for %d of %d\n",bytePos, -			lengthRetrieve, length); -		return; +		Platform::DebugPrintf("Bad GetCharRange %d for %d of %d\n", bytePos, +		                      lengthRetrieve, length); +		return ;  	}  	GapTo(0); 	// Move the buffer so its easy to subscript into it  	char *pb = part2body + bytePos;  	while (lengthRetrieve--) {  		*buffer++ = *pb; -		pb +=2; +		pb += 2;  	}  } @@ -716,7 +721,7 @@ void CellBuffer::InsertCharStyle(int position, char ch, char style) {  }  bool CellBuffer::SetStyleAt(int position, char style, char mask) { -	char curVal = ByteAt(position*2 + 1); +	char curVal = ByteAt(position * 2 + 1);  	if ((curVal & mask) != style) {  		SetByteAt(position*2 + 1, static_cast<char>((curVal & ~mask) | style));  		return true; @@ -833,7 +838,7 @@ int CellBuffer::LineFromHandle(int markerHandle) {  void CellBuffer::BasicInsertString(int position, char *s, int insertLength) {  	//Platform::DebugPrintf("Inserting at %d for %d\n", position, insertLength);  	if (insertLength == 0) -		return; +		return ;  	RoomFor(insertLength);  	GapTo(position); @@ -893,7 +898,7 @@ void CellBuffer::BasicInsertString(int position, char *s, int insertLength) {  void CellBuffer::BasicDeleteChars(int position, int deleteLength) {  	//Platform::DebugPrintf("Deleting at %d for %d\n", position, deleteLength);  	if (deleteLength == 0) -		return; +		return ;  	if ((position == 0) && (deleteLength == length)) {  		// If whole buffer is being deleted, faster to reinitialise lines data @@ -925,6 +930,7 @@ void CellBuffer::BasicDeleteChars(int position, int deleteLength) {  			ignoreNL = true; 	// First \n is not real deletion  		} +  		char ch = chNext;  		for (int i = 0; i < deleteLength; i += 2) {  			chNext = ' '; @@ -942,6 +948,7 @@ void CellBuffer::BasicDeleteChars(int position, int deleteLength) {  				ignoreNL = false; 	// Further \n are not real deletions  			} +  			ch = chNext;  		}  		// May have to fix up end if last deletion causes cr to be next to lf @@ -1004,12 +1011,12 @@ void CellBuffer::PerformUndoStep() {  		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; +			styledData[i*2 + 1] = 0;  		}  		BasicInsertString(actionStep.position, styledData, actionStep.lenData*2);  		delete []styledData;  	} -    uh.CompletedUndoStep(); +	uh.CompletedUndoStep();  }  bool CellBuffer::CanRedo() { @@ -1030,14 +1037,14 @@ void CellBuffer::PerformRedoStep() {  		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; +			styledData[i*2 + 1] = 0;  		}  		BasicInsertString(actionStep.position, styledData, actionStep.lenData*2);  		delete []styledData;  	} else if (actionStep.at == removeAction) {  		BasicDeleteChars(actionStep.position, actionStep.lenData*2);  	} -    uh.CompletedRedoStep(); +	uh.CompletedRedoStep();  }  int CellBuffer::SetLineState(int line, int state) { @@ -1053,7 +1060,7 @@ int CellBuffer::GetLineState(int line) {  int CellBuffer::GetMaxLineState() {  	return lineStates.Length();  } -		 +  int CellBuffer::SetLevel(int line, int level) {  	int prev = 0;  	if ((line >= 0) && (line < lv.lines)) { @@ -1077,5 +1084,5 @@ int CellBuffer::GetLevel(int line) {  }  void CellBuffer::ClearLevels() { -    lv.ClearLevels(); +	lv.ClearLevels();  }  | 
