Skip to content

Commit dbefcac

Browse files
authored
fix(fx): commit proxy port field on focus loss, not only on Enter (#512)
1 parent b61a87a commit dbefcac

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

‎jsignpdf/src/main/java/net/sf/jsignpdf/fx/view/TsaSettingsController.java‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,14 @@ private void bindToViewModel() {
140140
// Proxy port: String <-> int
141141
viewModel.proxyPortProperty().addListener((obs, o, n) ->
142142
txtProxyPort.setText(String.valueOf(n.intValue())));
143-
txtProxyPort.setOnAction(e -> {
144-
try {
145-
viewModel.proxyPortProperty().set(Integer.parseInt(txtProxyPort.getText()));
146-
} catch (NumberFormatException ignored) {
143+
txtProxyPort.setOnAction(e -> commitProxyPort());
144+
// Enter alone misses the common case of typing a value and then clicking elsewhere
145+
// (e.g. Save, or another field) without pressing Enter first: the text field shows the
146+
// typed value, but it is never written back to the model, so signing silently falls back
147+
// to the last committed port (Constants.DEFVAL_PROXY_PORT, 80, if none was ever committed).
148+
txtProxyPort.focusedProperty().addListener((obs, o, isFocused) -> {
149+
if (!isFocused) {
150+
commitProxyPort();
147151
}
148152
});
149153

@@ -168,6 +172,16 @@ private void bindToViewModel() {
168172
txtProxyPort.setManaged(proxyOn);
169173
}
170174

175+
private void commitProxyPort() {
176+
try {
177+
viewModel.proxyPortProperty().set(Integer.parseInt(txtProxyPort.getText()));
178+
} catch (NumberFormatException ignored) {
179+
// Invalid entry (empty, non-numeric): revert the field to the last committed
180+
// value rather than silently keeping an un-persisted port on screen.
181+
txtProxyPort.setText(String.valueOf(viewModel.proxyPortProperty().get()));
182+
}
183+
}
184+
171185
private void applyAuthVisibility(ServerAuthentication authn) {
172186
tsaUserPane.setVisible(authn == ServerAuthentication.PASSWORD);
173187
tsaCertPane.setVisible(authn == ServerAuthentication.CERTIFICATE);

0 commit comments

Comments
 (0)