Index: generic/tkText.c ================================================================== --- generic/tkText.c +++ generic/tkText.c @@ -2768,11 +2768,11 @@ /* Index describing first location. */ const TkTextIndex *index2Ptr) /* Index describing second location. */ { TkUndoSubAtom *iAtom, *dAtom; - TkUndoAtom *redoElem, *undoElem; + int canUndo, canRedo; /* * Create the helpers. */ @@ -2855,12 +2855,12 @@ Tcl_DecrRefCount(seeInsertObj); Tcl_DecrRefCount(index1Obj); Tcl_DecrRefCount(index2Obj); - undoElem = textPtr->sharedTextPtr->undoStack->undoStack; - redoElem = textPtr->sharedTextPtr->undoStack->redoStack; + canUndo = TkUndoCanUndo(textPtr->sharedTextPtr->undoStack); + canRedo = TkUndoCanRedo(textPtr->sharedTextPtr->undoStack); /* * Depending whether the action is to insert or delete, we provide the * appropriate second and third arguments to TkUndoPushAction. (The first * is the 'actionCommand', and the second the 'revertCommand'). @@ -2870,11 +2870,11 @@ TkUndoPushAction(textPtr->sharedTextPtr->undoStack, iAtom, dAtom); } else { TkUndoPushAction(textPtr->sharedTextPtr->undoStack, dAtom, iAtom); } - if (undoElem == NULL || redoElem != NULL) { + if (!canUndo || canRedo) { GenerateUndoStackEvent(textPtr); } } /* @@ -5164,11 +5164,10 @@ Tcl_Obj *const objv[]) /* Argument objects. */ { int index, setModified, oldModified; int canRedo = 0; int canUndo = 0; - TkUndoAtom *redoElem, *undoElem; static const char *const editOptionStrings[] = { "canundo", "canredo", "modified", "redo", "reset", "separator", "undo", NULL }; @@ -5247,30 +5246,30 @@ case EDIT_REDO: if (objc != 3) { Tcl_WrongNumArgs(interp, 3, objv, NULL); return TCL_ERROR; } - undoElem = textPtr->sharedTextPtr->undoStack->undoStack; + canUndo = TkUndoCanUndo(textPtr->sharedTextPtr->undoStack); if (TextEditRedo(textPtr)) { Tcl_SetObjResult(interp, Tcl_NewStringObj("nothing to redo", -1)); Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_REDO", NULL); return TCL_ERROR; } - redoElem = textPtr->sharedTextPtr->undoStack->redoStack; - if (undoElem == NULL || redoElem == NULL) { + canRedo = TkUndoCanRedo(textPtr->sharedTextPtr->undoStack); + if (!canUndo || !canRedo) { GenerateUndoStackEvent(textPtr); } break; case EDIT_RESET: if (objc != 3) { Tcl_WrongNumArgs(interp, 3, objv, NULL); return TCL_ERROR; } - undoElem = textPtr->sharedTextPtr->undoStack->undoStack; - redoElem = textPtr->sharedTextPtr->undoStack->redoStack; + canUndo = TkUndoCanUndo(textPtr->sharedTextPtr->undoStack); + canRedo = TkUndoCanRedo(textPtr->sharedTextPtr->undoStack); TkUndoClearStacks(textPtr->sharedTextPtr->undoStack); - if (undoElem != NULL || redoElem != NULL) { + if (canUndo || canRedo) { GenerateUndoStackEvent(textPtr); } break; case EDIT_SEPARATOR: if (objc != 3) { @@ -5282,18 +5281,18 @@ case EDIT_UNDO: if (objc != 3) { Tcl_WrongNumArgs(interp, 3, objv, NULL); return TCL_ERROR; } - redoElem = textPtr->sharedTextPtr->undoStack->redoStack; + canRedo = TkUndoCanRedo(textPtr->sharedTextPtr->undoStack); if (TextEditUndo(textPtr)) { Tcl_SetObjResult(interp, Tcl_NewStringObj("nothing to undo", -1)); Tcl_SetErrorCode(interp, "TK", "TEXT", "NO_UNDO", NULL); return TCL_ERROR; } - undoElem = textPtr->sharedTextPtr->undoStack->undoStack; - if (redoElem == NULL || undoElem == NULL) { + canUndo = TkUndoCanUndo(textPtr->sharedTextPtr->undoStack); + if (!canRedo || !canUndo) { GenerateUndoStackEvent(textPtr); } break; } return TCL_OK; Index: generic/tkUndo.c ================================================================== --- generic/tkUndo.c +++ generic/tkUndo.c @@ -493,21 +493,11 @@ int TkUndoCanRedo( TkUndoRedoStack *stack) /* An Undo/Redo stack */ { - int canRedo = 0; - TkUndoAtom *elem = stack->redoStack; - - while (elem != NULL) { - if (elem->type != TK_UNDO_SEPARATOR) { - canRedo = 1; - break; - } - elem = elem->next; - } - return canRedo; + return stack->redoStack != NULL; } /* *---------------------------------------------------------------------- * @@ -526,21 +516,11 @@ int TkUndoCanUndo( TkUndoRedoStack *stack) /* An Undo/Redo stack */ { - int canUndo = 0; - TkUndoAtom *elem = stack->undoStack; - - while (elem != NULL) { - if (elem->type != TK_UNDO_SEPARATOR) { - canUndo = 1; - break; - } - elem = elem->next; - } - return canUndo; + return stack->undoStack != NULL; } /* *---------------------------------------------------------------------- *