Skip to content

Instantly share code, notes, and snippets.

@jonathanmaron
Created September 10, 2025 12:15
Show Gist options
  • Save jonathanmaron/ca8e46c74a24fefee77f6b18a1fd7d3e to your computer and use it in GitHub Desktop.
Save jonathanmaron/ca8e46c74a24fefee77f6b18a1fd7d3e to your computer and use it in GitHub Desktop.
// Global variables
let copiedFormat = null;
let styleCounter = 1;
let customStyles = {};
// Promise wrappers for TX Text Control API
const get = (method) =>
new Promise((resolve, reject) =>
TXTextControl.selection[method](v => resolve(v), e => reject(e))
);
const set = (method, val) =>
new Promise((resolve, reject) =>
TXTextControl.selection[method](val, () => resolve(), e => reject(e))
);
const getLength = () =>
new Promise((resolve, reject) =>
TXTextControl.selection.getLength(v => resolve(v), e => reject(e))
);
const selectWord = () =>
new Promise((resolve, reject) =>
TXTextControl.selectWord(() => resolve(), e => reject(e))
);
// Utility function to check if selected text has uniform formatting
function isCommonValueSelectedAsync(selection, attr) {
return new Promise((resolve, reject) => {
selection.isCommonSelectionValueSelected(
attr,
(result) => {
resolve(result); // true/false
},
reject
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment