Tk Source Code

View Ticket
Login
Ticket UUID: 3288113
Title: Missing marks when searched through mark next
Type: Bug Version: obsolete: 8.6b2
Submitter: fvogel Created on: 2011-04-16 06:30:17
Subsystem: 18. [text] Assigned To: jan.nijtmans
Priority: 7 High Severity:
Status: Closed Last Modified: 2014-03-13 09:01:24
Resolution: Fixed Closed By: nijtmans
    Closed on: 2012-01-22 16:19:11
Description:
I have a text widget with a peer. I set a mark in it and later I need to find out the list of marks the text widget contains. I need to be able to do this from any peer.

In the documentation, marks are advertised to be shared between peers so that they can be manipulated on an equal basis from any peer.

I have found this to be true for
  [$w mark names]
but apparently not for
  [$w mark next $ind]

[$w mark names] correctly returns all mark names, regardless of $w being the "initial" text widget, or the peer.

However, when scanning through the widget using [$w mark next $ind], I have found marks to be missing.

The following script demonstrates the problem:

------------

text .t
.t insert end "Hello\nworld\n"
.t peer create .pt
.t mark set mymark 2.0

# the text widget and its peer now have three marks:
# insert current mymark

# all three marks are found for both the text widget
# and its peer - OK!
tk_messageBox -message "[.t mark names]\n[.pt mark names]"

proc getmks {w} {
  set lstmks [list ]
  set mk [$w mark next 1.0]
  while {$mk ne ""} {
    lappend lstmks $mk
    set mk [$w mark next $mk]
  }
  return $lstmks
}

# all three marks are found ONLY for the text widget
# BUT NOT for its peer - BUG?
tk_messageBox -message "[getmks .t]\n[getmks .pt]"

------------

This is on Windows XP with Tcl/Tk 8.5.9, and it happens also on Vista with 8.6b1.
User Comments: nijtmans added on 2012-01-22 23:19:11:
Proposed patch applied to trunk and core-8-5-branch. Everything looks OK to me.

fvogelnew1 added on 2012-01-10 21:26:56:
I have proposed a patch fixing this issue, see #3471873:

https://sourceforge.net/tracker/?func=detail&aid=3471873&group_id=12997&atid=312997

I'm setting the "Assigned" field to the maintainer of the [text] area for patch review.

fvogelnew1 added on 2012-01-07 22:03:55:
tkTextMark.c

Creating a mark from a text widget sets  markPtr->body.mark.textPtr  to  textPtr  i.e. to the text widget from which the mark was created.

When running the mark next command later, this mark can only be retrieved if mark next is run from the *same* text widget the mark was created from.
Peers are explicitely excluded because of this snippet in MarkFindNext:

} else if (segPtr->body.mark.textPtr != textPtr) {
    /*
     * Ignore widget-specific marks for the other widgets.
     */
            continue;

I don't understand the purpose of this code above.
Simply removing the above test causes crashing on the last line (.pt mark next current) of the test case I gave below.

What's the logic behind body.mark.textPtr and what is the purpose of this check?

fvogelnew1 added on 2011-07-07 03:32:51:
Rediscovered (got bitten by) this issue once more!

I provided a test case and admitted I'm not proficient enough to provide a patch, despite I tried (see below).

Help, anyone?

dkf added on 2011-04-19 15:27:56:
You've got a test case, that's a really good point to hand over.

fvogelnew1 added on 2011-04-19 13:30:31:
I have spent a fair amount of time in the source code, but I don't understand how this can be happening.

MarkFindNext in tkTextMark.c should access the same sharedTextPtr->markTable be it from the initial text widget or from any of its peers. That's just the exact purpose of the sharedTextPtr structure.

Indeed TkTextMarkCmd in the part for MARK_NAMES accesses this same sharedTextPtr->markTable, and this works correctly from the initial text widget or from its peers.

One level above, CreateWidget in tkText.c seems to do the adequate thing when creating both the initial text widget and when creating its peers, i.e. the sharedPtr is correctly (and differently) managed in each case.

Summing up, I do not see where the problem is.
I unfortunately lack debugging tools (Windows) to go on diving in this.

fvogelnew1 added on 2011-04-19 13:21:25:
Simple test:

text .t
.t peer create .pt
.t mark set mymark 1.0
.t mark next 1.0   ; # returns "mymark"
.pt mark next 1.0      ; # returns "insert"
.pt mark next insert   ; # returns "current"
.pt mark next current  ; # returns "" -> where is "mymark"???