Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Curse is a library for capturing and restoring selections—primarily for use in
HTML elements that are contenteditable
, where text may stay the same, but
the rendered HTML may change.
bower install curse
Create a new Curse
and pass it an HTMLElement
. The curse is capable of
capturing and restoring the user's selection inside of that element.
var element = document.querySelector('#editor');
var curse = new Curse(element);
element.innerText = 'Hello world';
// User selects "llo w"
curse.capture(); // Capture the current cursor or selection
element.innerText = 'Hello, world';
curse.restore(); // Restore the user's selection.
Note that a Curse
is dumb. In the above example, if the user's selection was
"llo w"
, after the text was changed and the cursor restored, the user's
selection would have been "llo, "
. It is up to the implementer to handle
changes in text length by adjusting curse.start
and curse.end
:
element.innerText = 'Hello world';
// User selects "llo w"
curse.capture();
element.innerText = 'Hello, world';
curse.end++;
curse.restore(); // Selection is "llo, w"
It's possible that depending on your setup, you may need to pass a custom
function to a Curse to count node length. This can be done by passing
nodeLengthFn
:
let curse = new Curse(element, { nodeLengthFn: nodeLengthFn });
function nodeLengthFn(node, __super) {
if (node.classList.contains('Foo')) {
return 12;
} else {
/*
* `__super` can be called to call the original `nodeLength` function on the
* given node.
*/
return __super();
}
}
Curse still gets a little confused when it sees certain types of HTML elements in a contenteditable. If you run across something, please open an issue.
Tests use testem and run in the Chrome browser.
Install:
git clone git@github.com:slowink/curse.git
cd curse
npm install
Test:
npm test
In order to run the example page (useful for experimentation):
npm run dev
FAQs
A user selection caching utility
The npm package cursejs receives a total of 19 weekly downloads. As such, cursejs popularity was classified as not popular.
We found that cursejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.