Skip to content

Commit

Permalink
chore: Added some additional APIs to work with dom (#4719)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnester authored May 30, 2022
1 parent 3b36762 commit 29ef318
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
11 changes: 8 additions & 3 deletions lib/ace/keyboard/textinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,8 @@ var TextInput = function(parentNode, host) {
// allows to ignore composition (used by vim keyboard handler in the normal mode)
// this is useful on mac, where with some keyboard layouts (e.g swedish) ^ starts composition
this.setCommandMode = function(value) {
commandMode = value;
text.readOnly = false;
commandMode = value;
text.readOnly = false;
};

this.setReadOnly = function(readOnly) {
Expand Down Expand Up @@ -666,7 +666,7 @@ var TextInput = function(parentNode, host) {
function addIosSelectionHandler(parentNode, host, text) {
var typingResetTimeout = null;
var typing = false;

text.addEventListener("keydown", function (e) {
if (typingResetTimeout) clearTimeout(typingResetTimeout);
typing = true;
Expand Down Expand Up @@ -748,6 +748,11 @@ var TextInput = function(parentNode, host) {
document.removeEventListener("selectionchange", detectArrowKeys);
});
}

this.destroy = function() {
if (text.parentElement)
text.parentElement.removeChild(text);
};
};

exports.TextInput = TextInput;
Expand Down
23 changes: 16 additions & 7 deletions lib/ace/lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ exports.getDocumentHead = function(doc) {

exports.createElement = function(tag, ns) {
return document.createElementNS ?
document.createElementNS(ns || XHTML_NS, tag) :
document.createElement(tag);
document.createElementNS(ns || XHTML_NS, tag) :
document.createElement(tag);
};

exports.removeChildren = function(element) {
Expand Down Expand Up @@ -158,9 +158,9 @@ exports.toggleCssClass = function(el, name) {


/*
* Add or remove a CSS class from the list of classes on the given node
* depending on the value of <tt>include</tt>
*/
* Add or remove a CSS class from the list of classes on the given node
* depending on the value of <tt>include</tt>
*/
exports.setCssClass = function(node, className, include) {
if (include) {
exports.addCssClass(node, className);
Expand All @@ -173,9 +173,18 @@ exports.hasCssString = function(id, doc) {
var index = 0, sheets;
doc = doc || document;
if ((sheets = doc.querySelectorAll("style"))) {
while (index < sheets.length)
if (sheets[index++].id === id)
while (index < sheets.length) {
if (sheets[index++].id === id) {
return true;
}
}
}
};

exports.removeElementById = function(id, doc) {
doc = doc || document;
if(doc.getElementById(id)) {
doc.getElementById(id).remove();
}
};

Expand Down

0 comments on commit 29ef318

Please sign in to comment.