diff options
| author | Neil <nyamatongwe@gmail.com> | 2021-04-05 16:34:10 +1000 | 
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2021-04-05 16:34:10 +1000 | 
| commit | 088d8034e79e7e2e44a114a2dc203bda5518dd49 (patch) | |
| tree | d16ca55ee0799b7bb076807240935e17688bc2cf | |
| parent | 9f9b24ae9bc0ae771454732868cdb136fe995e42 (diff) | |
| download | scintilla-mirror-088d8034e79e7e2e44a114a2dc203bda5518dd49.tar.gz | |
Change actionType to an enum class.
| -rw-r--r-- | src/CellBuffer.cxx | 54 | ||||
| -rw-r--r-- | src/CellBuffer.h | 8 | ||||
| -rw-r--r-- | src/Document.cxx | 30 | 
3 files changed, 46 insertions, 46 deletions
| diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 21fbb7003..767a0c30d 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -303,7 +303,7 @@ public:  };  Action::Action() noexcept { -	at = startAction; +	at = ActionType::start;  	position = 0;  	lenData = 0;  	mayCoalesce = false; @@ -312,7 +312,7 @@ Action::Action() noexcept {  Action::~Action() {  } -void Action::Create(actionType at_, Sci::Position position_, const char *data_, Sci::Position lenData_, bool mayCoalesce_) { +void Action::Create(ActionType at_, Sci::Position position_, const char *data_, Sci::Position lenData_, bool mayCoalesce_) {  	data = nullptr;  	position = position_;  	at = at_; @@ -356,7 +356,7 @@ UndoHistory::UndoHistory() {  	savePoint = 0;  	tentativePoint = -1; -	actions[currentAction].Create(startAction); +	actions[currentAction].Create(ActionType::start);  }  UndoHistory::~UndoHistory() { @@ -371,7 +371,7 @@ void UndoHistory::EnsureUndoRoom() {  	}  } -const char *UndoHistory::AppendAction(actionType at, Sci::Position position, const char *data, Sci::Position lengthData, +const char *UndoHistory::AppendAction(ActionType at, Sci::Position position, const char *data, Sci::Position lengthData,  	bool &startSequence, bool mayCoalesce) {  	EnsureUndoRoom();  	//Platform::DebugPrintf("%% %d action %d %d %d\n", at, position, lengthData, currentAction); @@ -387,7 +387,7 @@ const char *UndoHistory::AppendAction(actionType at, Sci::Position position, con  			int targetAct = -1;  			const Action *actPrevious = &(actions[currentAction + targetAct]);  			// Container actions may forward the coalesce state of Scintilla Actions. -			while ((actPrevious->at == containerAction) && actPrevious->mayCoalesce) { +			while ((actPrevious->at == ActionType::container) && actPrevious->mayCoalesce) {  				targetAct--;  				actPrevious = &(actions[currentAction + targetAct]);  			} @@ -400,15 +400,15 @@ const char *UndoHistory::AppendAction(actionType at, Sci::Position position, con  				currentAction++;  			} else if (!mayCoalesce || !actPrevious->mayCoalesce) {  				currentAction++; -			} else if (at == containerAction || actions[currentAction].at == containerAction) { +			} else if (at == ActionType::container || actions[currentAction].at == ActionType::container) {  				;	// A coalescible containerAction -			} else if ((at != actPrevious->at) && (actPrevious->at != startAction)) { +			} else if ((at != actPrevious->at) && (actPrevious->at != ActionType::start)) {  				currentAction++; -			} else if ((at == insertAction) && +			} else if ((at == ActionType::insert) &&  			           (position != (actPrevious->position + actPrevious->lenData))) {  				// Insertions must be immediately after to coalesce  				currentAction++; -			} else if (at == removeAction) { +			} else if (at == ActionType::remove) {  				if ((lengthData == 1) || (lengthData == 2)) {  					if ((position + lengthData) == actPrevious->position) {  						; // Backspace -> OK @@ -438,7 +438,7 @@ const char *UndoHistory::AppendAction(actionType at, Sci::Position position, con  	const int actionWithData = currentAction;  	actions[currentAction].Create(at, position, data, lengthData, mayCoalesce);  	currentAction++; -	actions[currentAction].Create(startAction); +	actions[currentAction].Create(ActionType::start);  	maxAction = currentAction;  	return actions[actionWithData].data.get();  } @@ -446,9 +446,9 @@ const char *UndoHistory::AppendAction(actionType at, Sci::Position position, con  void UndoHistory::BeginUndoAction() {  	EnsureUndoRoom();  	if (undoSequenceDepth == 0) { -		if (actions[currentAction].at != startAction) { +		if (actions[currentAction].at != ActionType::start) {  			currentAction++; -			actions[currentAction].Create(startAction); +			actions[currentAction].Create(ActionType::start);  			maxAction = currentAction;  		}  		actions[currentAction].mayCoalesce = false; @@ -461,9 +461,9 @@ void UndoHistory::EndUndoAction() {  	EnsureUndoRoom();  	undoSequenceDepth--;  	if (0 == undoSequenceDepth) { -		if (actions[currentAction].at != startAction) { +		if (actions[currentAction].at != ActionType::start) {  			currentAction++; -			actions[currentAction].Create(startAction); +			actions[currentAction].Create(ActionType::start);  			maxAction = currentAction;  		}  		actions[currentAction].mayCoalesce = false; @@ -479,7 +479,7 @@ void UndoHistory::DeleteUndoHistory() {  		actions[i].Clear();  	maxAction = 0;  	currentAction = 0; -	actions[currentAction].Create(startAction); +	actions[currentAction].Create(ActionType::start);  	savePoint = 0;  	tentativePoint = -1;  } @@ -508,7 +508,7 @@ bool UndoHistory::TentativeActive() const noexcept {  int UndoHistory::TentativeSteps() noexcept {  	// Drop any trailing startAction -	if (actions[currentAction].at == startAction && currentAction > 0) +	if (actions[currentAction].at == ActionType::start && currentAction > 0)  		currentAction--;  	if (tentativePoint >= 0)  		return currentAction - tentativePoint; @@ -522,12 +522,12 @@ bool UndoHistory::CanUndo() const noexcept {  int UndoHistory::StartUndo() {  	// Drop any trailing startAction -	if (actions[currentAction].at == startAction && currentAction > 0) +	if (actions[currentAction].at == ActionType::start && currentAction > 0)  		currentAction--;  	// Count the steps in this action  	int act = currentAction; -	while (actions[act].at != startAction && act > 0) { +	while (actions[act].at != ActionType::start && act > 0) {  		act--;  	}  	return currentAction - act; @@ -547,12 +547,12 @@ bool UndoHistory::CanRedo() const noexcept {  int UndoHistory::StartRedo() {  	// Drop any leading startAction -	if (currentAction < maxAction && actions[currentAction].at == startAction) +	if (currentAction < maxAction && actions[currentAction].at == ActionType::start)  		currentAction++;  	// Count the steps in this action  	int act = currentAction; -	while (act < maxAction && actions[act].at != startAction) { +	while (act < maxAction && actions[act].at != ActionType::start) {  		act++;  	}  	return act - currentAction; @@ -647,7 +647,7 @@ const char *CellBuffer::InsertString(Sci::Position position, const char *s, Sci:  		if (collectingUndo) {  			// Save into the undo/redo stack, but only the characters - not the formatting  			// This takes up about half load time -			data = uh.AppendAction(insertAction, position, s, insertLength, startSequence); +			data = uh.AppendAction(ActionType::insert, position, s, insertLength, startSequence);  		}  		BasicInsertString(position, s, insertLength); @@ -696,7 +696,7 @@ const char *CellBuffer::DeleteChars(Sci::Position position, Sci::Position delete  			// Save into the undo/redo stack, but only the characters - not the formatting  			// The gap would be moved to position anyway for the deletion so this doesn't cost extra  			data = substance.RangePointer(position, deleteLength); -			data = uh.AppendAction(removeAction, position, data, deleteLength, startSequence); +			data = uh.AppendAction(ActionType::remove, position, data, deleteLength, startSequence);  		}  		BasicDeleteChars(position, deleteLength); @@ -1246,7 +1246,7 @@ void CellBuffer::EndUndoAction() {  void CellBuffer::AddUndoAction(Sci::Position token, bool mayCoalesce) {  	bool startSequence; -	uh.AppendAction(containerAction, token, nullptr, 0, startSequence, mayCoalesce); +	uh.AppendAction(ActionType::container, token, nullptr, 0, startSequence, mayCoalesce);  }  void CellBuffer::DeleteUndoHistory() { @@ -1267,13 +1267,13 @@ const Action &CellBuffer::GetUndoStep() const {  void CellBuffer::PerformUndoStep() {  	const Action &actionStep = uh.GetUndoStep(); -	if (actionStep.at == insertAction) { +	if (actionStep.at == ActionType::insert) {  		if (substance.Length() < actionStep.lenData) {  			throw std::runtime_error(  				"CellBuffer::PerformUndoStep: deletion must be less than document length.");  		}  		BasicDeleteChars(actionStep.position, actionStep.lenData); -	} else if (actionStep.at == removeAction) { +	} else if (actionStep.at == ActionType::remove) {  		BasicInsertString(actionStep.position, actionStep.data.get(), actionStep.lenData);  	}  	uh.CompletedUndoStep(); @@ -1293,9 +1293,9 @@ const Action &CellBuffer::GetRedoStep() const {  void CellBuffer::PerformRedoStep() {  	const Action &actionStep = uh.GetRedoStep(); -	if (actionStep.at == insertAction) { +	if (actionStep.at == ActionType::insert) {  		BasicInsertString(actionStep.position, actionStep.data.get(), actionStep.lenData); -	} else if (actionStep.at == removeAction) { +	} else if (actionStep.at == ActionType::remove) {  		BasicDeleteChars(actionStep.position, actionStep.lenData);  	}  	uh.CompletedRedoStep(); diff --git a/src/CellBuffer.h b/src/CellBuffer.h index 599b6062f..43ee0d884 100644 --- a/src/CellBuffer.h +++ b/src/CellBuffer.h @@ -25,14 +25,14 @@ public:   */  class ILineVector; -enum actionType { insertAction, removeAction, startAction, containerAction }; +enum class ActionType { insert, remove, start, container };  /**   * Actions are used to store all the information required to perform one undo/redo step.   */  class Action {  public: -	actionType at; +	ActionType at;  	Sci::Position position;  	std::unique_ptr<char[]> data;  	Sci::Position lenData; @@ -46,7 +46,7 @@ public:  	// Move constructor allows vector to be resized without reallocating.  	Action(Action &&other) noexcept = default;  	~Action(); -	void Create(actionType at_, Sci::Position position_=0, const char *data_=nullptr, Sci::Position lenData_=0, bool mayCoalesce_=true); +	void Create(ActionType at_, Sci::Position position_=0, const char *data_=nullptr, Sci::Position lenData_=0, bool mayCoalesce_=true);  	void Clear() noexcept;  }; @@ -72,7 +72,7 @@ public:  	void operator=(UndoHistory &&) = delete;  	~UndoHistory(); -	const char *AppendAction(actionType at, Sci::Position position, const char *data, Sci::Position lengthData, bool &startSequence, bool mayCoalesce=true); +	const char *AppendAction(ActionType at, Sci::Position position, const char *data, Sci::Position lengthData, bool &startSequence, bool mayCoalesce=true);  	void BeginUndoAction();  	void EndUndoAction(); diff --git a/src/Document.cxx b/src/Document.cxx index 63b90d69f..4548064b5 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -273,10 +273,10 @@ void Document::TentativeUndo() {  			for (int step = 0; step < steps; step++) {  				const Sci::Line prevLinesTotal = LinesTotal();  				const Action &action = cb.GetUndoStep(); -				if (action.at == removeAction) { +				if (action.at == ActionType::remove) {  					NotifyModified(DocModification(  									SC_MOD_BEFOREINSERT | SC_PERFORMED_UNDO, action)); -				} else if (action.at == containerAction) { +				} else if (action.at == ActionType::container) {  					DocModification dm(SC_MOD_CONTAINER | SC_PERFORMED_UNDO);  					dm.token = action.position;  					NotifyModified(dm); @@ -285,15 +285,15 @@ void Document::TentativeUndo() {  									SC_MOD_BEFOREDELETE | SC_PERFORMED_UNDO, action));  				}  				cb.PerformUndoStep(); -				if (action.at != containerAction) { +				if (action.at != ActionType::container) {  					ModifiedAt(action.position);  				}  				int modFlags = SC_PERFORMED_UNDO;  				// With undo, an insertion action becomes a deletion notification -				if (action.at == removeAction) { +				if (action.at == ActionType::remove) {  					modFlags |= SC_MOD_INSERTTEXT; -				} else if (action.at == insertAction) { +				} else if (action.at == ActionType::insert) {  					modFlags |= SC_MOD_DELETETEXT;  				}  				if (steps > 1) @@ -1326,10 +1326,10 @@ Sci::Position Document::Undo() {  			for (int step = 0; step < steps; step++) {  				const Sci::Line prevLinesTotal = LinesTotal();  				const Action &action = cb.GetUndoStep(); -				if (action.at == removeAction) { +				if (action.at == ActionType::remove) {  					NotifyModified(DocModification(  									SC_MOD_BEFOREINSERT | SC_PERFORMED_UNDO, action)); -				} else if (action.at == containerAction) { +				} else if (action.at == ActionType::container) {  					DocModification dm(SC_MOD_CONTAINER | SC_PERFORMED_UNDO);  					dm.token = action.position;  					NotifyModified(dm); @@ -1344,14 +1344,14 @@ Sci::Position Document::Undo() {  									SC_MOD_BEFOREDELETE | SC_PERFORMED_UNDO, action));  				}  				cb.PerformUndoStep(); -				if (action.at != containerAction) { +				if (action.at != ActionType::container) {  					ModifiedAt(action.position);  					newPos = action.position;  				}  				int modFlags = SC_PERFORMED_UNDO;  				// With undo, an insertion action becomes a deletion notification -				if (action.at == removeAction) { +				if (action.at == ActionType::remove) {  					newPos += action.lenData;  					modFlags |= SC_MOD_INSERTTEXT;  					if ((coalescedRemoveLen > 0) && @@ -1364,7 +1364,7 @@ Sci::Position Document::Undo() {  					}  					prevRemoveActionPos = action.position;  					prevRemoveActionLen = action.lenData; -				} else if (action.at == insertAction) { +				} else if (action.at == ActionType::insert) {  					modFlags |= SC_MOD_DELETETEXT;  					coalescedRemovePos = -1;  					coalescedRemoveLen = 0; @@ -1406,10 +1406,10 @@ Sci::Position Document::Redo() {  			for (int step = 0; step < steps; step++) {  				const Sci::Line prevLinesTotal = LinesTotal();  				const Action &action = cb.GetRedoStep(); -				if (action.at == insertAction) { +				if (action.at == ActionType::insert) {  					NotifyModified(DocModification(  									SC_MOD_BEFOREINSERT | SC_PERFORMED_REDO, action)); -				} else if (action.at == containerAction) { +				} else if (action.at == ActionType::container) {  					DocModification dm(SC_MOD_CONTAINER | SC_PERFORMED_REDO);  					dm.token = action.position;  					NotifyModified(dm); @@ -1418,16 +1418,16 @@ Sci::Position Document::Redo() {  									SC_MOD_BEFOREDELETE | SC_PERFORMED_REDO, action));  				}  				cb.PerformRedoStep(); -				if (action.at != containerAction) { +				if (action.at != ActionType::container) {  					ModifiedAt(action.position);  					newPos = action.position;  				}  				int modFlags = SC_PERFORMED_REDO; -				if (action.at == insertAction) { +				if (action.at == ActionType::insert) {  					newPos += action.lenData;  					modFlags |= SC_MOD_INSERTTEXT; -				} else if (action.at == removeAction) { +				} else if (action.at == ActionType::remove) {  					modFlags |= SC_MOD_DELETETEXT;  				}  				if (steps > 1) | 
