mirror of
https://github.com/logseq/logseq.git
synced 2026-04-30 00:46:23 +00:00
fix: get-selection-text not working on Firefox
This commit is contained in:
@@ -54,3 +54,21 @@ export var timeConversion = function (millisec) {
|
||||
return days + "d"
|
||||
}
|
||||
}
|
||||
|
||||
export var getSelectionText = function() {
|
||||
const selection = (window.getSelection() || '').toString().trim();
|
||||
if (selection) {
|
||||
return selection;
|
||||
}
|
||||
|
||||
// Firefox fix
|
||||
const activeElement = window.document.activeElement;
|
||||
if (activeElement) {
|
||||
if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') {
|
||||
const el = activeElement;
|
||||
return el.value.slice(el.selectionStart || 0, el.selectionEnd || 0);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user