Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select Geocoder text on focus. Fixes #4268. #4464

Merged
merged 4 commits into from
Oct 20, 2016
Merged

Select Geocoder text on focus. Fixes #4268. #4464

merged 4 commits into from
Oct 20, 2016

Conversation

twpayne
Copy link
Contributor

@twpayne twpayne commented Oct 19, 2016

cc @hpinkos

Slightly different code might be required for older iOS devices, see discussion on StackOverflow.

@@ -70,6 +70,11 @@ value: searchText,\
valueUpdate: "afterkeydown",\
disable: isSearchInProgress,\
css: { "cesium-geocoder-input-wide" : keepExpanded || searchText.length > 0 }');
textBox.addEventListener('focus', function() {
setTimeout(function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of the setTimeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScript cargo-culting :) This StackOverflow answer says "In Chrome the selection via .select() doesn't stick - adding a slight timeout resolves this issue.".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried the latest version of Chrome/Firefox/IE and everything worked fine without the timeout, so we can remove it to start and add it back if it's ever needed.

The general strategy for Cesium development is to target the latest version of the 5 major browsers (especially since 5 of them are evergreen) and only extra code for older browsers if its really needed and has wide enough use (and we can actually replicate the broken behavior we are fixing first).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried on the latest version of Safari (10.0 (12602.1.50.0.10)), and it seems that setTimeout is needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks for checking. Can you add a comment to the code indicating the setTimeout is needed for Safari, this way someone doesn't accidentally remove it in the future. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@hpinkos
Copy link
Contributor

hpinkos commented Oct 20, 2016

Thanks @twpayne! The functionality is great.

My only other comment is that we should call textBox.removeEventListener(... in Geocoder.prototype.destroy

@hpinkos hpinkos self-assigned this Oct 20, 2016
@twpayne
Copy link
Contributor Author

twpayne commented Oct 20, 2016

My only other comment is that we should call textBox.removeEventListener(... in Geocoder.prototype.destroy

Done.

@@ -164,6 +175,7 @@ cesiumSvgPath: { path: isSearchInProgress ? _stopSearchPath : _startSearchPath,

knockout.cleanNode(this._form);
this._container.removeChild(this._form);
this._textBox.removeEventListener(this._onTextBoxFocus, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be this._textBox.removeEventListener('focus', this._onTextBoxFocus, false);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh! Good catch. Sorry. Fixed.

@hpinkos
Copy link
Contributor

hpinkos commented Oct 20, 2016

Perfect, thanks @twpayne!

@hpinkos hpinkos merged commit 460357c into CesiumGS:master Oct 20, 2016
@hpinkos
Copy link
Contributor

hpinkos commented Oct 20, 2016

I'll update CHANGES.md in master

@twpayne twpayne deleted the geocoder-highlight-on-click branch October 20, 2016 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants