Move into monaco-editor-samples folder

This commit is contained in:
Alex Dima 2021-11-05 12:12:35 +01:00
parent b9969d41cb
commit a9ab892f7a
No known key found for this signature in database
GPG key ID: 39563C1504FDD0C9
86 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<h2>Monaco Diff Editor Sample</h2>
<div id="container" style="width: 800px; height: 600px; border: 1px solid grey"></div>
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
<script>
require.config({ paths: { vs: '../node_modules/monaco-editor/min/vs' } });
require(['vs/editor/editor.main'], function () {
var diffEditor = monaco.editor.createDiffEditor(document.getElementById('container'));
Promise.all([xhr('original.txt'), xhr('modified.txt')]).then(function (r) {
var originalTxt = r[0].responseText;
var modifiedTxt = r[1].responseText;
diffEditor.setModel({
original: monaco.editor.createModel(originalTxt, 'javascript'),
modified: monaco.editor.createModel(modifiedTxt, 'javascript')
});
});
});
</script>
<script>
function xhr(url) {
var req = null;
return new Promise(
function (c, e) {
req = new XMLHttpRequest();
req.onreadystatechange = function () {
if (req._canceled) {
return;
}
if (req.readyState === 4) {
if ((req.status >= 200 && req.status < 300) || req.status === 1223) {
c(req);
} else {
e(req);
}
req.onreadystatechange = function () {};
}
};
req.open('GET', url, true);
req.responseType = '';
req.send(null);
},
function () {
req._canceled = true;
req.abort();
}
);
}
</script>
</body>
</html>

View file

@ -0,0 +1,74 @@
/// <reference path="../../references.js" />
(function () {
"use strict";
var deltaDecorations = function (oldDecorations, newDecorations) {
/// <summary>
/// Update oldDecorations to match newDecorations.
/// It will remove old decorations which are not found in new decorations
/// and add only the really new decorations.
/// </summary>
/// <param name="oldDecorations" type="Array">
/// An array containing ids of existing decorations
/// </param>
/// <param name="newDecorations" type="Array">
/// An array containing literal objects describing new decorations. A
/// literal contains the following two fields:
/// range
/// options
/// </param>
/// <returns type="Array">
/// Returns an array of decorations ids
/// </returns>
var hashFunc = function (range, options) {
return range.startLineNumber + "," + range.startColumn + "-" + range.endLineNumber + "," + range.endColumn +
"-" + options.hoverMessage + "-" + options.className + "-" + options.isOverlay + "-" + options.showInOverviewRuler;
};
return this.changeDecorations(function (changeAccessor) {
var i, len, oldDecorationsMap = {}, hash;
// Record old decorations in a map
// Two decorations can have the same hash
for (i = 0, len = oldDecorations.length; i < len; i++) {
hash = hashFunc(this.getDecorationRange(oldDecorations[i]), this.getDecorationOptions(oldDecorations[i]));
oldDecorationsMap[hash] = oldDecorationsMap[hash] || [];
oldDecorationsMap[hash].push(oldDecorations[i]);
}
// Add only new decorations & mark reused ones
var j, lenJ, result = [], usedOldDecorations = {}, oldDecorationsCandidates, reusedOldDecoration;
for (i = 0, len = newDecorations.length; i < len; i++) {
hash = hashFunc(newDecorations[i].range, newDecorations[i].options);
reusedOldDecoration = false;
if (oldDecorationsMap.hasOwnProperty(hash)) {
oldDecorationsCandidates = oldDecorationsMap[hash];
// We can try reusing an old decoration (if it hasn't been reused before)
for (j = 0, lenJ = oldDecorationsCandidates.length; j < lenJ; j++) {
if (!usedOldDecorations.hasOwnProperty(oldDecorationsCandidates[j])) {
// Found an old decoration which can be reused & it hasn't been reused before
reusedOldDecoration = true;
usedOldDecorations[oldDecorationsCandidates[j]] = true;
result.push(oldDecorationsCandidates[j]);
break;
}
}
}
if (!reusedOldDecoration) {
result.push(changeAccessor.addDecoration(newDecorations[i].range, newDecorations[i].options));
}
}
// Remove unused old decorations
for (i = 0, len = oldDecorations.length; i < len; i++) {
if (!usedOldDecorations.hasOwnProperty(oldDecorations[i])) {
changeAccessor.removeDecoration(oldDecorations[i]);
}
}
return result;
}.bind(this));
};
})();

View file

@ -0,0 +1,61 @@
/// <reference path="../../references.js" />
(function () {
"use strict";
// Some useless comment
var deltaDecorations = function (oldDecorations, newDecorations) {
/// <summary>
/// Update oldDecorations to match newDecorations.
/// It will remove old decorations which are not found in new decorations
/// and add only the really new decorations.
/// </summary>
/// <param name="oldDecorations" type="Array">
/// An array containing ids of existing decorations
/// </param>
/// <param name="newDecorations" type="Array">
/// An array containing literal objects describing new decorations. A
/// literal contains the following two fields:
/// range
/// options
/// </param>
/// <returns type="Array">
/// Returns an array of decorations ids
/// </returns>
var hashFunc = function (range, options) {
return range.startLineNumber + "," + range.startColumn + "-" + range.endLineNumber + "," + range.endColumn +
"-" + options.hoverMessage + "-" + options.className + "-" + options.isOverlay + "-" + options.showInOverviewRuler;
};
return this.changeDecorations(function (changeAccessor) {
var i, len, oldDecorationsMap = {}, hash;
// Record old decorations in a map
for (i = 0, len = oldDecorations.length; i < len; i++) {
hash = hashFunc(this.getDecorationRange(oldDecorations[i]), this.getDecorationOptions(oldDecorations[i]));
oldDecorationsMap[hash] = i;
}
// Add only new decorations & mark reused ones
var result = [], usedOldDecorationsMap = {};
for (i = 0, len = newDecorations.length; i < len; i++) {
hash = hashFunc(newDecorations[i].range, newDecorations[i].options);
if (oldDecorationsMap.hasOwnProperty(hash)) {
usedOldDecorationsMap[oldDecorationsMap[hash]] = true;
result.push(oldDecorations[oldDecorationsMap[hash]]);
} else {
result.push(changeAccessor.addDecoration(newDecorations[i].range, newDecorations[i].options));
}
}
// Remove unused old decorations
for (i = 0, len = oldDecorations.length; i < len; i++) {
if (!usedOldDecorationsMap.hasOwnProperty(i)) {
changeAccessor.removeDecoration(oldDecorations[i]);
}
}
return result;
}.bind(this));
};
})();