- Break out contents of poorly named function (punction?) "this_ones_a_frame_changer"
- Remove need for setTimeout
main
Isaiah Odhner 2019-12-08 09:07:31 -05:00
parent 79ed512449
commit 0e3e90e170
4 changed files with 30 additions and 16 deletions

View File

@ -241,10 +241,10 @@ class OnCanvasSelection extends OnCanvasObject {
}
// eslint-disable-next-line no-empty
catch (e) { }
$G.triggerHandler("session-update"); // autosave
}
destroy() {
super.destroy();
$G.triggerHandler("session-update"); // what does this mean, and why is it needed?
$G.off("option-changed", this._on_option_changed);
update_helper_layer(); // TODO: under-grid specific helper layer?
}

View File

@ -44,8 +44,6 @@
}
});
$G.on("session-update.ugly-hook", () => {
setTimeout(may_be_changed);
});
$G.on("session-update.ugly-hook", may_be_changed);
})();

View File

@ -309,7 +309,9 @@ function open_from_Image(img, callback, canceled){
are_you_sure(() => {
// TODO: shouldn't open_from_* start a new session?
this_ones_a_frame_changer();
deselect();
cancel();
saved = false;
reset_file();
reset_colors();
@ -319,6 +321,7 @@ function open_from_Image(img, callback, canceled){
ctx.copy(img);
detect_transparency();
$canvas_area.trigger("resize");
$G.triggerHandler("session-update"); // autosave
callback && callback();
}, canceled);
@ -408,12 +411,16 @@ function open_from_FileList(files, user_input_method_verb_past_tense){
function file_new(){
are_you_sure(() => {
this_ones_a_frame_changer();
deselect();
cancel();
saved = false;
reset_file();
reset_colors();
reset_canvas_and_history(); // (with newly reset colors)
set_magnification(default_magnification);
$G.triggerHandler("session-update"); // autosave
});
}
@ -942,25 +949,33 @@ function undoable(callback, action){
}
function undo(){
if(undos.length<1){ return false; }
this_ones_a_frame_changer();
deselect();
cancel();
saved = false;
redos.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
ctx.copy(undos.pop());
$canvas_area.trigger("resize");
$G.triggerHandler("session-update"); // autosave
return true;
}
function redo(){
if(redos.length<1){ return false; }
this_ones_a_frame_changer();
deselect();
cancel();
saved = false;
undos.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
ctx.copy(redos.pop());
$canvas_area.trigger("resize");
$G.triggerHandler("session-update"); // autosave
return true;
}
@ -978,12 +993,6 @@ function cancel(){
}
update_helper_layer();
}
function this_ones_a_frame_changer(){
deselect();
saved = false;
cancel();
$G.triggerHandler("session-update");
}
function deselect(){
if(selection){
selection.draw();
@ -1156,7 +1165,9 @@ function image_invert(){
function clear(){
undoable(0, () => {
this_ones_a_frame_changer();
deselect();
cancel();
saved = false;
if(transparency){
ctx.clearRect(0, 0, canvas.width, canvas.height);
@ -1164,6 +1175,8 @@ function clear(){
ctx.fillStyle = colors.background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
$G.triggerHandler("session-update"); // autosave
});
}

View File

@ -372,11 +372,14 @@ function apply_image_transformation(fn){
selection.replace_source_canvas(new_canvas);
}else{
undoable(0, () => {
this_ones_a_frame_changer();
deselect();
cancel();
saved = false;
ctx.copy(new_canvas);
$canvas.trigger("update"); // update handles
$G.triggerHandler("session-update"); // autosave
});
}
}