Giter Site home page Giter Site logo

Feature request: undo/redo about teehee HOT 1 CLOSED

maximbaz avatar maximbaz commented on May 15, 2024
Feature request: undo/redo

from teehee.

Comments (1)

Gskartwii avatar Gskartwii commented on May 15, 2024 1

Hey! Thanks for your kind words, I really appreciate it.

Undo and redo are a very good and essential idea. I have already started working on them, though I've got a brick wall because I'm confused by the API of the underlying to byte string rope.

teehee/src/history.rs

Lines 38 to 76 in deafef8

fn chain(self, after_self: &Rope, next: RopeDelta) -> Action {
let after_next = after_self.apply_delta(&next);
let (ins1, del1) = self.delta.factor();
let (ins2, del2) = next.factor();
let inserted_first = ins1.inserted_subset();
let del1_expanded = del1.transform_expand(&inserted_first);
let inserted_in_mid_text = inserted_first.transform_shrink(&del1_expanded);
let inserted_second = ins2.inserted_subset();
let inserted_total = inserted_in_mid_text.transform_union(&inserted_second);
let del2_expanded = del2.transform_expand(&inserted_second);
let inserted_in_next_text = inserted_total.transform_shrink(&del2_expanded);
let tombstones = after_next.without_subset(inserted_in_next_text.complement());
let ins2_in_final_union = ins2
.transform_expand(&del1_expanded, true)
.inserted_subset();
/*let ins1_in_final_union = ins1
.transform_shrink(&del1_expanded)
.transform_expand(&inserted_second, false)
.inserted_subset();
let insertions_in_final_union = ins1_in_final_union.union(&ins2_in_final_union);*/
let insertions_in_final_union = dbg!(ins1
.transform_shrink(&del1_expanded)
.transform_expand(dbg!(&inserted_second), false)
.inserted_subset());
let deletions_from_final = del2_expanded
.transform_union(&del1_expanded)
.transform_expand(&insertions_in_final_union);
Action {
delta: RopeDelta::synthesize(
&tombstones.into_node(),
dbg!(&insertions_in_final_union),
dbg!(&deletions_from_final),
),
}
}
}

The above function is meant to be able to chain together two deltas (for example two byte insertions in Insert mode) into a single delta, so that an Insert mode change can be stored in a memory efficient manner. I'm just not quite able to work out how to construct the delta, though I will be making an effort to work on this between everything else. Feel free to advise me if you have an idea on that!

from teehee.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.