1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-08 23:29:42 +00:00

editor setText() does minimum change for undo

This commit is contained in:
Steven Hugg 2019-03-27 09:02:01 -04:00
parent 6cea0772bf
commit c794a43004
5 changed files with 42 additions and 13 deletions

View File

@ -13,6 +13,13 @@
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--> <![endif]-->
<link href="https://fonts.googleapis.com/css?family=Exo" rel="stylesheet">
<style type="text/css" media="screen">
body {
font-family: 'Exo', sans-serif;
}
</style>
<script> <script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
if (window.location.host.endsWith('8bitworkshop.com')) { if (window.location.host.endsWith('8bitworkshop.com')) {

View File

@ -109,6 +109,8 @@ TODO:
- update nested data, palette/tile refs properly - update nested data, palette/tile refs properly
- throw errors when bad/no refs - throw errors when bad/no refs
- careful with mouse capture out of frame - careful with mouse capture out of frame
- per-View keyboard shortcuts
- global undo
WEB WORKER FORMAT WEB WORKER FORMAT

View File

@ -81,8 +81,9 @@ export class SourceEditor implements ProjectView {
parent.appendChild(div); parent.appendChild(div);
var asmOverride = text && this.mode=='verilog' && /__asm\b([\s\S]+?)\b__endasm\b/.test(text); var asmOverride = text && this.mode=='verilog' && /__asm\b([\s\S]+?)\b__endasm\b/.test(text);
this.newEditor(div, asmOverride); this.newEditor(div, asmOverride);
if (text) if (text) {
this.setText(text); // TODO: this calls setCode() and builds... it shouldn't this.setText(text); // TODO: this calls setCode() and builds... it shouldn't
}
this.setupEditor(); this.setupEditor();
return div; return div;
} }
@ -141,8 +142,19 @@ export class SourceEditor implements ProjectView {
} }
setText(text:string) { setText(text:string) {
this.editor.setValue(text); // calls setCode() var i,j;
this.editor.clearHistory(); var oldtext = this.editor.getValue();
if (oldtext != text) {
// find minimum range to undo
for (var i=0; i<oldtext.length && i<text.length && text[i] == oldtext[i]; i++) { }
for (var j=0; j<oldtext.length && j<text.length && text[text.length-1-j] == oldtext[oldtext.length-1-j]; j++) { }
//console.log(i,j,oldtext.substring(i,oldtext.length-j));
this.replaceSelection(i, oldtext.length-j, text.substring(i, text.length-j)); // calls setCode()
// clear history if setting empty editor
if (oldtext == '') {
this.editor.clearHistory();
}
}
} }
insertText(text:string) { insertText(text:string) {
@ -150,6 +162,11 @@ export class SourceEditor implements ProjectView {
this.editor.replaceRange(text, cur, cur); this.editor.replaceRange(text, cur, cur);
} }
replaceSelection(start:number, end:number, text:string) {
this.editor.setSelection(this.editor.posFromIndex(start), this.editor.posFromIndex(end));
this.editor.replaceSelection(text);
}
getValue() : string { getValue() : string {
return this.editor.getValue(); return this.editor.getValue();
} }
@ -349,11 +366,6 @@ export class SourceEditor implements ProjectView {
return -1; return -1;
} }
replaceSelection(start:number, end:number, text:string) {
this.editor.setSelection(end, start);
this.editor.replaceSelection(text);
}
} }
/// ///

View File

@ -28,16 +28,24 @@ export class ProjectWindows {
this.id2createfn[id] = createfn; this.id2createfn[id] = createfn;
} }
createOrShow(id:string) : ProjectView { create(id:string) : ProjectView {
var wnd = this.id2window[id]; var wnd = this.id2window[id];
if (!wnd) { if (!wnd) {
console.log("creating window",id);
wnd = this.id2window[id] = this.id2createfn[id](id); wnd = this.id2window[id] = this.id2createfn[id](id);
} }
var div = this.id2div[id]; var div = this.id2div[id];
if (!div) { if (!div) {
var data = this.project.getFile(id)+""; // TODO: binary files var data = this.project.getFile(id)+""; // TODO: binary files
div = this.id2div[id] = wnd.createDiv(this.containerdiv, data); div = this.id2div[id] = wnd.createDiv(this.containerdiv, data);
$(div).hide();
} }
return wnd;
}
createOrShow(id:string) : ProjectView {
var wnd = this.create(id);
var div = this.id2div[id];
if (this.activewnd != wnd) { if (this.activewnd != wnd) {
if (this.activediv) if (this.activediv)
$(this.activediv).hide(); $(this.activediv).hide();
@ -103,9 +111,10 @@ export class ProjectWindows {
this.createOrShow(this.activeid); this.createOrShow(this.activeid);
} }
} }
updateFile(fileid : string, data : FileData) { updateFile(fileid:string, data:FileData) {
var wnd = this.id2window[fileid]; // is there an editor? we should create one...
var wnd = this.create(fileid);
if (wnd && wnd.setText && typeof data === 'string') { if (wnd && wnd.setText && typeof data === 'string') {
wnd.setText(data); wnd.setText(data);
} else { } else {

View File

@ -1912,7 +1912,6 @@ function executeBuildSteps() {
var toolfn = TOOLS[step.tool]; var toolfn = TOOLS[step.tool];
if (!toolfn) throw "no tool named " + step.tool; if (!toolfn) throw "no tool named " + step.tool;
step.params = PLATFORM_PARAMS[getBasePlatform(platform)]; step.params = PLATFORM_PARAMS[getBasePlatform(platform)];
console.log(step.platform + " " + step.tool);
try { try {
step.result = toolfn(step); step.result = toolfn(step);
} catch (e) { } catch (e) {