Skip to content

Commit bb34c35

Browse files
committed
fix: live code hints gets dismissed when pressing arrow keys
1 parent 593d5df commit bb34c35

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/editor/EditorHelper/ChangeHelper.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ define(function (require, exports, module) {
202202
// If self editor is visible, close all dropdowns on scroll.
203203
// (We don't want to do self if we're just scrolling in a non-visible editor
204204
// in response to some document change event.)
205-
if (self.isFullyVisible()) {
205+
if (!self._shouldNotDismissPopupsOnScroll && self.isFullyVisible()) {
206206
Menus.closeAll();
207207
}
208208

@@ -244,6 +244,29 @@ define(function (require, exports, module) {
244244
});
245245
}
246246

247+
/**
248+
* will not dismiss any popups on scrolling the editor till the given timout
249+
* @param {number} [timeoutMs]
250+
* @private
251+
*/
252+
function _dontDismissPopupOnScroll(timeoutMs = 500) {
253+
// eslint-disable-next-line no-invalid-this
254+
const self = this;
255+
// on live code hints, when the user is selecting code hints using arrow keys, the text in the editor changes.
256+
// If the text that is being changed falls beyond the editor border(Eg: end of a long line that is part occluded
257+
// by live preview panel), then cm will scroll the editor horizontally to show the changed text. On scrolling,
258+
// all popups are usually dismissed(see scroll event handler in this file), but that should happen if we
259+
// are live code hinting. So we do this.
260+
if(self._shouldNotDismissPopupsOnScroll){
261+
clearTimeout(self._shouldNotDismissPopupsOnScroll);
262+
}
263+
self._shouldNotDismissPopupsOnScroll = setTimeout(()=>{
264+
// we only wait for 500 ms after the user pressed up or down arrow key, after which its any scroll will
265+
// dismiss all popups. This is os that user may scroll the text using mouse which should dismiss popups.
266+
self._shouldNotDismissPopupsOnScroll = false;
267+
}, timeoutMs);
268+
}
269+
247270
/**
248271
* add required helpers to editor
249272
* @param Editor
@@ -256,6 +279,7 @@ define(function (require, exports, module) {
256279
Editor.prototype._handleDocumentDeleted = _handleDocumentDeleted;
257280
Editor.prototype._handleDocumentLanguageChanged = _handleDocumentLanguageChanged;
258281
Editor.prototype._installEditorListeners = _installEditorListeners;
282+
Editor.prototype._dontDismissPopupOnScroll = _dontDismissPopupOnScroll;
259283
}
260284

261285
exports.addHelpers =addHelpers;

src/extensions/default/CSSCodeHints/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ define(function (require, exports, module) {
442442
return;
443443
}
444444
isInLiveHighlightSession = true;
445+
this.editor._dontDismissPopupOnScroll();
445446
this.editor.restoreHistoryPoint(`${HISTORY_PREFIX}${hintSessionId}`);
446447
this.insertHint($highlightedEl.find(".brackets-css-hints"), true);
447448
};

src/extensions/default/HTMLCodeHints/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ define(function (require, exports, module) {
391391
return;
392392
}
393393
isInLiveHighlightSession = true;
394+
this.editor._dontDismissPopupOnScroll();
394395
this.editor.restoreHistoryPoint(`${HISTORY_PREFIX}${hintSessionId}`);
395396
this.insertHint($highlightedEl.find(".brackets-html-hints"), true);
396397
};

0 commit comments

Comments
 (0)