question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

caret and anchor stale after selectRange with listeners

See original GitHub issue

If you attempt to use selectRange to update caret and anchor positions that have attached listeners, the caret and anchor potitions will be stale.

@Test fun `sscce`(){
    val underTest = StyleClassedTextArea()

    //comment out this line of code and the test passes
    val dontCare = Bindings.createStringBinding(Callable { "binded" }, underTest.caretPositionProperty(), underTest.anchorProperty())
    underTest.appendText("asdf")
    
    //act
    underTest.selectRange(1, 2)

    //assert
    assertThat(underTest.selectedText).isEqualTo("s") //OK
    assertThat(listOf(underTest.anchor, underTest.caretPosition)).isEqualTo(listOf(1, 2)) //fail
    //actual: 0, 2
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Groostavcommented, Dec 4, 2019

@Jugen No I did mean anchor position. The caret appears to be working correctly.

Firstly: the use case is to have a richTextFX text area, with a couple of labels bound to metadata about that text areas selection --a pretty common thing if you look at gedit or notepad++.

I’ve found that if I leave my selection-listeners on the text area it changes the behaviour of the text area. Text selection with the mouse becomes stunted and heavily prone to artificially moving the caret to the end of the document or the anchor to the beginning of the document. This is what lead to the original report. Since your fix the behaviour got better but it is not corrected. If I leave my selection-listeners on the text area, I still find it selecting the wrong ranges frequently.

I have tried to get this down to an SSCCE but have had difficulty.

But I have found a workaround: rather than bind to the anchorProperty and the caretPositionProperty, I’m simply binding to the selectedTextProperty.

I still need to do some work here, I’ll let you know when I’ve got something reasonably actionable for you, but this one is tricky to run down.

probably what an “SSCCE” is going to look like is a live UI with some console output, and then a statement that “this console output should not be here”.

0reactions
Jugencommented, Dec 1, 2019

Umm, did you maybe mean caret position and not anchor position ? Otherwise can you provide more information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firing an event when the caret gets within a particular div/span ...
This will let you know when your caret position is in an anchor node containing an @. $('#content').on('mouseup keydown keyup', ...
Read more >
third_party/WebKit/Source/web/WebViewImpl.cpp - Google Git
Constants for viewport anchoring on resize. ... static const int minReadableCaretHeight = 16; ... stale if this WebView is embedded in another one....
Read more >
Safari Technology Preview Release Notes - Apple Developer
Many of the new Safari 16 features are now available in Safari Technology Preview 147: Live Text. Select and interact with text in...
Read more >
Micetro by Menamp;Mice Documentation
The DHCP software (ISC DHCP) on the Men&Mice Virtual Appliances was patched for the ... or the FQDN of the availability group listener:....
Read more >
Developers' handbook - MuseScore
Accessibility with focus on visually impaired musicians ... Audience Score Following: score following for audiences using node.js - Video ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found