Explicitly modify undoable when finalizing selection

- Conditionally create an undoable for Deselect in case there's a Session Sync update in between selecting and deselecting (in Multi-User mode), and otherwise modify the undoable for Select/Free-Form Select
- Multi-User: Don't sync to the database CONSTANTLY while smearing a selection! (I should still add debouncing!)
main
Isaiah Odhner 2019-12-12 13:00:30 -05:00
parent f9c5903400
commit 94d9c82e09
4 changed files with 25 additions and 17 deletions

View File

@ -277,7 +277,19 @@ class OnCanvasSelection extends OnCanvasObject {
}
// eslint-disable-next-line no-empty
catch (e) { }
$G.triggerHandler("session-update"); // autosave
}
meld_into_canvas() {
this.draw();
// TODO: create soft undoable, never modify undoables
if (current_history_node.name.match(/Select/i)) {
current_history_node.image_data = ctx.getImageData(0, 0, canvas.width, canvas.height);
$G.triggerHandler("session-update"); // autosave
} else {
undoable("Deselect", ()=> {
this.draw();
}, get_icon_for_tool(get_tool_by_name("Select")), false, true);
}
this.destroy();
}
destroy() {
super.destroy();

View File

@ -123,7 +123,8 @@ class OnCanvasTextBox extends OnCanvasObject {
this.y = Math.max(Math.min(m.y - moy, canvas.height), -this.height);
this.position();
if (e.shiftKey) {
this.draw();
// TODO: maybe re-enable but handle undoables well
// this.draw();
}
};
this.$el.on("pointerdown", e => {
@ -171,13 +172,14 @@ class OnCanvasTextBox extends OnCanvasObject {
super.position(true);
update_helper_layer(); // TODO: under-grid specific helper layer?
}
draw() {
meld_into_canvas() {
const text = this.$editor.val();
if (text) {
undoable("Text", () => {
ctx.drawImage(this.canvas, this.x, this.y);
}, get_icon_for_tool(get_tool_by_name("Text")));
}
this.destroy();
}
destroy() {
super.destroy();

View File

@ -983,9 +983,9 @@ function go_to_history_node(target_history_node, canceling) {
$G.triggerHandler("session-update"); // autosave
$G.triggerHandler("history-update"); // update history view
}
function undoable(action_name, callback, icon, is_extra_undoable_for_unknown){
function undoable(action_name, callback, icon, is_extra_undoable_for_unknown, prevent_extra_undoable_for_unknown){
// TODO: only modify undoables explicitly elsewhere (or create soft undoables)
if (!is_extra_undoable_for_unknown) {
if (!is_extra_undoable_for_unknown && !prevent_extra_undoable_for_unknown) {
const current_image_data = ctx.getImageData(0, 0, canvas.width, canvas.height);
if (!current_history_node.image_data || !image_data_are_equal(current_history_node.image_data, current_image_data)) {
// console.log("modifying undoable", current_history_node, "previous image_data:", current_history_node.image_data);
@ -1154,13 +1154,11 @@ function cancel(going_to_history_node){
}
function deselect(){
if(selection){
selection.draw();
selection.destroy();
selection.meld_into_canvas();
selection = null;
}
if(textbox){
textbox.draw();
textbox.destroy();
textbox.meld_into_canvas();
textbox = null;
}
for (const selected_tool of selected_tools) {

View File

@ -95,8 +95,7 @@ window.tools = [{
if(selection){
// for silly multitools feature
alert("This isn't supposed to happen: Free-Form Select after Select in the tool chain?");
selection.draw();
selection.destroy();
selection.meld_into_canvas();
selection = null;
}
selection = new OnCanvasSelection(
@ -135,8 +134,7 @@ window.tools = [{
var free_form_selection = selection;
if(selection){
// for silly multitools feature
selection.draw();
selection.destroy();
selection.meld_into_canvas();
selection = null;
}
if (ctrl) {
@ -920,13 +918,11 @@ tools.forEach((tool)=> {
pointer_has_moved = true;
});
if(selection){
selection.draw();
selection.destroy();
selection.meld_into_canvas();
selection = null;
}
if(textbox){
textbox.draw();
textbox.destroy();
textbox.meld_into_canvas();
textbox = null;
}
$canvas_handles.hide();