Index: doc/text.n ================================================================== --- doc/text.n +++ doc/text.n @@ -485,10 +485,15 @@ .IP "\fBnone\fR" The new text will not receive any tags from surrounded text. .RE .OP \-undo undo Undo Specifies a boolean that says whether the undo mechanism is active or not. +.OP \-undotagging undoTagging UndoTagging +This boolean value specifies the setup value for \fB-undo\fR option when +creating tags. Per default the setup value is \fItrue\fR. Note that this +value will not be used for the special tag \fBsel\fR. See description of +tag option \fB-undo\fR for more information. .OP \-width width Width Specifies the desired width for the window in units of characters in the font given by the \fB\-font\fR option. If the font does not have a uniform width then the width of the character .QW 0 @@ -1114,12 +1119,13 @@ .TP \fB\-undo \fIboolean\fR . Specifies whether adding/removing this tag to/from text will be undone with \fBundo\fR operation. If this flag is \fIfalse\fR, then changes of tag -associations will not be undone for this tag. The default is \fItrue\fR, except -for the special selection flag \fBsel\fR, the default for this tag is \fIfalse\fR. +associations will not be undone for this tag. The default is given with +text option \fB-undotagging\fR (normally \fItrue\fR), except for the special +selection flag \fBsel\fR, the default for this tag is always \fIfalse\fR. .TP \fB\-wrap \fImode\fR . \fIMode\fR specifies how to handle lines that are wider than the text's window. This option only applies to a display line if it applies to the Index: generic/tkText.c ================================================================== --- generic/tkText.c +++ generic/tkText.c @@ -7,11 +7,11 @@ * and its actual display are implemented elsewhere. * * Copyright (c) 1992-1994 The Regents of the University of California. * Copyright (c) 1994-1996 Sun Microsystems, Inc. * Copyright (c) 1999 by Scriptics Corporation. - * Copyright (c) 2015-2017 Gregor Cramer + * Copyright (c) 2015-2018 Gregor Cramer * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ @@ -375,12 +375,12 @@ #endif {TK_OPTION_STRING_TABLE, "-state", "state", "State", DEF_TEXT_STATE, -1, Tk_Offset(TkText, state), 0, stateStrings, 0}, {TK_OPTION_BOOLEAN, "-steadymarks", "steadyMarks", "SteadyMarks", "0", -1, Tk_Offset(TkText, steadyMarks), TK_OPTION_DONT_SET_DEFAULT, 0, 0}, - {TK_OPTION_INT, "-synctime", "syncTime", "SyncTime", "150", -1, Tk_Offset(TkText, syncTime), - 0, 0, TK_TEXT_SYNCHRONIZE}, + {TK_OPTION_INT, "-synctime", "syncTime", "SyncTime", + "150", -1, Tk_Offset(TkText, syncTime), 0, 0, TK_TEXT_SYNCHRONIZE}, {TK_OPTION_STRING, "-tabs", "tabs", "Tabs", DEF_TEXT_TABS, Tk_Offset(TkText, tabOptionPtr), -1, TK_OPTION_NULL_OK, 0, TK_TEXT_LINE_GEOMETRY}, {TK_OPTION_STRING_TABLE, "-tabstyle", "tabStyle", "TabStyle", DEF_TEXT_TABSTYLE, -1, Tk_Offset(TkText, tabStyle), 0, tabStyleStrings, TK_TEXT_LINE_GEOMETRY}, {TK_OPTION_STRING_TABLE, "-tagging", "tagging", "Tagging", @@ -387,10 +387,12 @@ "within", -1, Tk_Offset(TkText, tagging), 0, taggingStrings, 0}, {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus", DEF_TEXT_TAKE_FOCUS, -1, Tk_Offset(TkText, takeFocus), TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_BOOLEAN, "-undo", "undo", "Undo", DEF_TEXT_UNDO, -1, Tk_Offset(TkText, undo), TK_OPTION_DONT_SET_DEFAULT, 0 ,0}, + {TK_OPTION_BOOLEAN, "-undotagging", "undoTagging", "UndoTagging", + "1", -1, Tk_Offset(TkText, undoTagging), 0, 0 ,0}, {TK_OPTION_BOOLEAN, "-useunibreak", "useUniBreak", "UseUniBreak", "0", -1, Tk_Offset(TkText, useUniBreak), 0, 0, TK_TEXT_LINE_GEOMETRY}, {TK_OPTION_INT, "-width", "width", "Width", DEF_TEXT_WIDTH, -1, Tk_Offset(TkText, width), 0, 0, TK_TEXT_LINE_GEOMETRY}, {TK_OPTION_STRING_TABLE, "-wrap", "wrap", "Wrap", @@ -1048,10 +1050,11 @@ sharedTextPtr->affectLineHeightTags = TkBitResize(NULL, TK_TEXT_SET_MAX_BIT_SIZE); sharedTextPtr->tagLookup = malloc(TK_TEXT_SET_MAX_BIT_SIZE*sizeof(TkTextTag *)); sharedTextPtr->emptyTagInfoPtr = TkTextTagSetResize(NULL, 0); sharedTextPtr->maxRedoDepth = -1; sharedTextPtr->autoSeparators = true; + sharedTextPtr->undoTagging = true; sharedTextPtr->lastEditMode = TK_TEXT_EDIT_OTHER; sharedTextPtr->lastUndoTokenType = -1; sharedTextPtr->startMarker = TkTextMakeStartEndMark(NULL, &tkTextLeftMarkType); sharedTextPtr->endMarker = TkTextMakeStartEndMark(NULL, &tkTextRightMarkType); sharedTextPtr->protectionMark[0] = TkTextMakeMark(NULL, NULL); @@ -1174,16 +1177,17 @@ TkTextCreateDInfo(textPtr); TkTextIndexSetupToStartOfText(&startIndex, textPtr, sharedTextPtr->tree); TkTextSetYView(textPtr, &startIndex, 0); textPtr->exportSelection = true; textPtr->pickEvent.type = LeaveNotify; - textPtr->steadyMarks = textPtr->sharedTextPtr->steadyMarks; - textPtr->undo = textPtr->sharedTextPtr->undo; - textPtr->maxUndoDepth = textPtr->sharedTextPtr->maxUndoDepth; - textPtr->maxRedoDepth = textPtr->sharedTextPtr->maxRedoDepth; - textPtr->maxUndoSize = textPtr->sharedTextPtr->maxUndoSize; - textPtr->autoSeparators = textPtr->sharedTextPtr->autoSeparators; + textPtr->steadyMarks = sharedTextPtr->steadyMarks; + textPtr->undo = sharedTextPtr->undo; + textPtr->maxUndoDepth = sharedTextPtr->maxUndoDepth; + textPtr->maxRedoDepth = sharedTextPtr->maxRedoDepth; + textPtr->maxUndoSize = sharedTextPtr->maxUndoSize; + textPtr->autoSeparators = sharedTextPtr->autoSeparators; + textPtr->undoTagging = sharedTextPtr->undoTagging; /* * Create the "sel" tag and the "current" and "insert" marks. * Note: it is important that textPtr->selTagPtr is NULL before this * initial call. @@ -3877,16 +3881,17 @@ Tk_SavedOptions savedOptions; TkTextIndex start, end, current; TkSizeT currentEpoch; TkSharedText *sharedTextPtr = textPtr->sharedTextPtr; TkTextBTree tree = sharedTextPtr->tree; + bool copyDownFlags = false; bool oldExport = (textPtr->exportSelection) && (!Tcl_IsSafe(textPtr->interp)); bool oldTextDebug = tkTextDebug; bool didHyphenate = textPtr->hyphenate; + bool oldUndoTagging = textPtr->undoTagging; int oldHyphenRules = textPtr->hyphenRules; int mask = 0; - bool copyDownFlags = false; tkTextDebug = false; /* debugging is not useful here */ #if SUPPORT_DEPRECATED_STARTLINE_ENDLINE @@ -4065,10 +4070,19 @@ } /* * Copy up shared flags. */ + + /* + * Update default value for undoing tag operations. + */ + + if (oldUndoTagging != textPtr->undoTagging) { + sharedTextPtr->undoTagging = textPtr->undoTagging; + copyDownFlags = true; + } /* This flag cannot alter if we have peers. */ sharedTextPtr->steadyMarks = textPtr->steadyMarks; if (sharedTextPtr->autoSeparators != textPtr->autoSeparators) { @@ -4131,10 +4145,11 @@ tPtr->autoSeparators = sharedTextPtr->autoSeparators; tPtr->maxUndoDepth = sharedTextPtr->maxUndoDepth; tPtr->maxRedoDepth = sharedTextPtr->maxRedoDepth; tPtr->maxUndoSize = sharedTextPtr->maxUndoSize; tPtr->undo = sharedTextPtr->undo; + tPtr->undoTagging = sharedTextPtr->undoTagging; } } /* * Check soft hyphen support. Index: generic/tkText.h ================================================================== --- generic/tkText.h +++ generic/tkText.h @@ -3,11 +3,11 @@ * * Declarations shared among the files that implement text widgets. * * Copyright (c) 1992-1994 The Regents of the University of California. * Copyright (c) 1994-1995 Sun Microsystems, Inc. - * Copyright (c) 2015-2017 Gregor Cramer + * Copyright (c) 2015-2018 Gregor Cramer * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ @@ -1200,10 +1200,11 @@ * Value 'true' is superseding the computed value, but value * 'false' is only clearing to the initial state of this flag. */ bool undoStackEvent; /* Flag indicating whether <> is already triggered. */ bool pushSeparator; /* Flag indicating whether a separator has to be pushed before next * insert/delete item. */ + bool undoTagging; /* Global default value for TkTextTag::undo. */ unsigned undoLevel; /* The undo level which corresponds to the unmodified state. */ TkTextEditMode lastEditMode;/* Keeps track of what the last edit mode was. */ int lastUndoTokenType; /* Type of newest undo token on stack. */ TkTextTag **undoTagList; /* Array of tags, prepared for undo stack. */ TkTextMarkChange *undoMarkList; @@ -1488,20 +1489,21 @@ int steadyMarks; /* false = behavior of original implementation, * true = new editor control mode. */ /* - * Copies of information from the shared section relating to the undo/redo functonality: + * Copies of information from the shared section relating to the undo/redo functionality: */ int undo; /* Non-zero means the undo/redo behaviour is enabled. */ int maxUndoDepth; /* The maximum depth of the undo stack expressed as the * maximum number of compound statements. */ int maxRedoDepth; /* The maximum depth of the redo stack expressed as the * maximum number of compound statements. */ int maxUndoSize; /* The maximum number of bytes kept on the undo stack. */ int autoSeparators; /* Non-zero means the separators will be inserted automatically. */ + bool undoTagging; /* Global default value for TkTextTag::undo. */ /* * Support of sync command: */ Index: generic/tkTextTag.c ================================================================== --- generic/tkTextTag.c +++ generic/tkTextTag.c @@ -5,11 +5,11 @@ * text widgets, plus most of the other high-level functions related to * tags. * * Copyright (c) 1992-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. - * Copyright (c) 2015-2017 Gregor Cramer + * Copyright (c) 2015-2018 Gregor Cramer * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ @@ -2023,29 +2023,29 @@ */ tagPtr = calloc(1, sizeof(TkTextTag)); tagPtr->name = name; tagPtr->index = index; - tagPtr->priority = textPtr->sharedTextPtr->numEnabledTags; + tagPtr->priority = sharedTextPtr->numEnabledTags; tagPtr->isSelTag = isSelTag; tagPtr->bgStipple = 0; tagPtr->fgStipple = 0; tagPtr->justify = TK_TEXT_JUSTIFY_LEFT; tagPtr->tabStyle = TK_TEXT_TABSTYLE_NONE; tagPtr->wrapMode = TEXT_WRAPMODE_NULL; - tagPtr->undo = !isSelTag; + tagPtr->undo = sharedTextPtr->undoTagging && !isSelTag; tagPtr->sharedTextPtr = sharedTextPtr; tagPtr->undoTagListIndex = -1; tagPtr->refCount = 1; tagPtr->tagEpoch = ++sharedTextPtr->tagEpoch; DEBUG_ALLOC(tkTextCountNewTag++); tagPtr->optionTable = Tk_CreateOptionTable(textPtr->interp, tagOptionSpecs); assert(!tagPtr->reliefPtr); - textPtr->sharedTextPtr->numTags += 1; - textPtr->sharedTextPtr->numEnabledTags += 1; + sharedTextPtr->numTags += 1; + sharedTextPtr->numEnabledTags += 1; if (isSelTag) { tagPtr->textPtr = textPtr; textPtr->refCount += 1; TkBitSet(sharedTextPtr->selectionTags, index); Index: tests/text.test ================================================================== --- tests/text.test +++ tests/text.test @@ -1082,10 +1082,27 @@ pack .t update } -body { .t configure -useunibreak eh } -cleanup { + destroy .t +} -match glob -returnCodes {error} -result {*} +test text-1.109 {configuration option: "undotagging"} -setup { + text .t + update +} -body { + .t configure -undotagging 0 + .t cget -undotagging +} -cleanup { + destroy .t +} -result {0} +test text-1.110 {configuration option: "undotagging"} -setup { + text .t + update +} -body { + .t configure -undotagging eh +} -cleanup { destroy .t } -match glob -returnCodes {error} -result {*} test text-2.1 {Tk_TextCmd procedure} -body { Index: tests/textTag.test ================================================================== --- tests/textTag.test +++ tests/textTag.test @@ -309,10 +309,29 @@ test textTag-1.37 {configuration options} -body { .t tag configure x -underlinecolor stupid } -cleanup { .t tag configure x -underlinecolor [lindex [.t tag configure x -underlinecolor] 3] } -returnCodes error -result {unknown color name "stupid"} +test textTag-1.38 {configuration options} -body { + .t tag configure x -undo eh +} -cleanup { + .t tag configure x -undo 1 +} -returnCodes error -result {expected boolean value but got "eh"} +test textTag-1.39 {configuration options} -setup { + .t tag configure x -underline [lindex [.t tag configure x -underline] 3] +} -body { + .t tag cget x -undo +} -result {1} +test textTag-1.40 {configuration options} -setup { + text .u +} -body { + .u configure -undotagging 0 + .u tag configure x -underline 0 + .u tag cget x -undo +} -cleanup { + destroy .u +} -result {0} test textTag-2.1 {TkTextTagCmd - "add" option} -body { .t tag } -returnCodes error -result {wrong # args: should be ".t tag option ?arg arg ...?"}