Release 3.1.0
New features
History extension
Previously, the browser's native undo/redo was used. While this often worked well enough, it has its limitations. In Chrome and Safari, all form elements share the same undo stack, and in Firefox, hiding an element with display: none
would clear its undo history. The new history extension has none of these issues. You can even transfer the history from an editor to another, but not without breaking the old editor.
The extension is tiny. Adding it to the demo website, only increases its JS bundle by 0.35kB gzipped.
The history extension has been added to the basic setup and the full setup. The extension can be accessed from PrismEditor.extensions
.
// Here's how to import the extension
import { editHistory } from "prism-code-editor/commands"
New theme
Prism's Tomorrow Night theme has been implemented. It's on the demo website if you want to try it.
Note: I forgot to add this file to the package. This was fixed in 3.1.2
import "prism-code-editor/themes/prism-tomorrow.css"
Improvements
- Significantly increased performance of the
getClosestToken()
utility, especially for long lines. This was achieved by using aTreeWalker
for the searching instead of usingquerySelector()
coupled withRange.toString()
to find the position of the tokens. The performance increase can be anywhere from a few times faster for short lines to a greater than 100x improvement for lines 1000s of characters long. Not sure why you'd view minified code in an editor, but that will perform much better now (9f8ebe6) - Decreased gzipped size of all Prism languages by more than 10kB (5%) through refactoring and optimization.
- An
input
event on the textarea now always updates the editor even if its value didn't change (7a3ddef)
Fixes
- Added
.js
extensions to most imports. The type declarations now work properly with amoduleResolution
ofNodeNext
orNode16
(b94978b) - Added
type="button"
to the copy button and all buttons in the search widget. If you had an editor inside a form, these buttons would previously submit the form when clicked. This is no longer the case (8ea416b) - Fixed potential empty matches that could lead to buggy highlighting in multiple languages (b28da8d)
- The
getLanguage()
utility now supports languages with hyphens in their name (d214971) - Changed the default tab size of the web components from 0 to 2 spaces. This wasn't a big issue since 0 would internally be replaced with 2 (e2ad6e5)
- Fixed alignment issue with the
highlightSelectionMatches()
extension in RTL mode (741bc85) - Fixed incorrect highlighting of capitalized generic functions in the TSX language (bf85599)
- Added a
language-jsx
alias to spread tokens inside JSX tags (bf85599)
Search widget improvments
- Selection change handlers no longer run with the incorrect selection after calling the
insertText()
utility if the search widget is open (7a3ddef) - Selection matches are no longer highlighted after replacing a match with the search widget (7a3ddef)
- The keyboard shortcuts for the 4 toggle buttons now uses
keyCode
instead ofcode
on Mac. This will work better with non-QWERTY keyboards on Mac (7a3ddef)