Reading and wiping notes also adding more notes

Joel joelcnz at gmail.com
Tue Oct 18 06:19:31 UTC 2022


On Tuesday, 18 October 2022 at 05:48:27 UTC, Ali Çehreli wrote:
> On 10/17/22 22:40, Joel wrote:
>
> > I have two text fields. The one on the left has the whole
> text, new
> > stuff being added to the bottom. The one on the right has
> text I've been
> > wiping as I'm reading.
>
> I think this can be modelled as a string array and an index 
> showing where the active part starts:
>
> import std;
>
> struct Notes {
>     string[] whole;
>     size_t activeIndex;
>
>     void add(string line) {
>         whole ~= line;
>     }
>
>     string[] activeText() {
>         return whole[activeIndex..$];
>     }
>
>     void wipeText() {
>         ++activeIndex;
>     }
> }
>
> void main() {
>     auto input = [ "I went for a walk and fell down a hole.",
>                    "There was a D guy on the roof.",
>                    "That was a tricky problem!", ];
>
>     Notes notes;
>
>     // add() to add()
>     input.each!(line => notes.add(line));
>
>     // activeText() will show the active part
>     // wipeText() will move forward
> }
>
> Ali

	void upNotes() {
		string left, right;

		left=_editBoxMain.text.to!string;
		right=_editBoxRight.text.to!string;

		// left is the whole doc
		// right is the read and wipe doc

		// Add the new stuff at the bottom of left and append it to the 
right

		size_t chunkSize=100;
		string chunkText, appendText;
		if (right.length<100)
			chunkSize=right.length;
		
		// mixin(tce("chunkSize left.length right.length 
right[$-chunkSize..$]".split));
		chunkText=left[$-chunkSize..$];

		size_t l=left.length-1, r=right.length-1;
		while(true) {
			if (right[r..$]!=left[l..$]) {
				r-=1;
				l-=1;
			} else
				break;
		}
		
		right=right~left[r..$]; //appendText;

		_editBoxRight.text=right.to!dstring;
	}


More information about the Digitalmars-d-learn mailing list