Skip to content

Commit

Permalink
Fixed: FileSelectionField - editing text field is difficult - cursor …
Browse files Browse the repository at this point in the history
…jumps to the end after each keystroke #27
  • Loading branch information
jpsacha committed Apr 4, 2024
1 parent 168f506 commit 710db6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2023, ScalaFX Project
* Copyright (c) 2011-2024, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -27,7 +27,7 @@

package org.scalafx.extras.generic_pane

import scalafx.application.Platform
import org.scalafx.extras.onFX
import scalafx.beans.property.StringProperty
import scalafx.scene.Node
import scalafx.scene.control.{Button, TextField}
Expand All @@ -44,7 +44,7 @@ object DirectorySelectionField {
* existing parent
*/
@tailrec
def existingOrParent(file: File): File =
private def existingOrParent(file: File): File =
if (file.exists()) file
else existingOrParent(file.getCanonicalFile.getParentFile)
}
Expand Down Expand Up @@ -90,14 +90,6 @@ class DirectorySelectionField(
prefColumnCount = columns
}

// Make sure that end of the file name is visible
textField.text.onChange { (_, _, _) =>
val location = textField.text.length.get()
Platform.runLater {
textField.positionCaret(location)
}
}

val button = new Button("Browse") {
onAction = _ => {
val initialPath = path.value
Expand All @@ -112,6 +104,7 @@ class DirectorySelectionField(
Option(selection).foreach { s =>
path.value = s.getCanonicalPath
lastDirectoryHandler.lastDirectory = s
onFX { textField.positionCaret(textField.text.length.get()) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2023, ScalaFX Project
* Copyright (c) 2011-2024, ScalaFX Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -27,7 +27,7 @@

package org.scalafx.extras.generic_pane

import scalafx.application.Platform
import org.scalafx.extras.onFX
import scalafx.beans.property.StringProperty
import scalafx.scene.Node
import scalafx.scene.control.{Button, TextField}
Expand Down Expand Up @@ -73,14 +73,6 @@ class FileSelectionField(
prefColumnCount = columns
}

// Make sure that end of the file name is visible
textField.text.onChange { (_, _, _) =>
val location = textField.text.length.get()
Platform.runLater {
textField.positionCaret(location)
}
}

val button = new Button("Browse") {
onAction = _ => {
val initialPath = path.value
Expand All @@ -101,6 +93,7 @@ class FileSelectionField(
Option(selection).foreach { s =>
path.value = s.getCanonicalPath
lastDirectoryHandler.lastDirectory = s
onFX { textField.positionCaret(textField.text.length.get()) }
}
}
}
Expand Down

0 comments on commit 710db6e

Please sign in to comment.