digitalmars.D.learn - Reading and wiping notes also adding more notes
- Joel (16/16) Oct 17 2022 I'm trying to add a feature to my text modifying program. I take
- =?UTF-8?Q?Ali_=c3=87ehreli?= (28/31) Oct 17 2022 I think this can be modelled as a string array and an index showing
I'm trying to add a feature to my text modifying program. I take a lot of notes but I want to be able to both wipe what I've read while still adding more notes as I go. 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 want to be able to add from the whole text just the new stuff at the bottom to the right text at the bottom. - I hope I'm making sense (good exercise, trying to explain it helps me work it out by itself). Example Whole text: [I went for a walk and fell down a hole. There was a D guy on the roof. That was a tricky problem!] Read and wipe text: [There was a d guy on the roof.] Now I want to add "That was a tricky problem!" to the wipe text to get: [There was a D guy on the roof. That was a tricky problem!]
Oct 17 2022
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
Oct 17 2022
On Tuesday, 18 October 2022 at 05:48:27 UTC, Ali Çehreli wrote:On 10/17/22 22:40, Joel wrote:I want to have two text files, for each notes I'm reading and wiping. Keep adding to one and reading wiping and updating the other one. I want my program to process them by updating the temporary notes.I have two text fields. The one on the left has the wholetext, newstuff being added to the bottom. The one on the right hastext I've beenwiping 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
Oct 17 2022
On Tuesday, 18 October 2022 at 05:48:27 UTC, Ali Çehreli wrote:On 10/17/22 22:40, Joel wrote: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; }I have two text fields. The one on the left has the wholetext, newstuff being added to the bottom. The one on the right hastext I've beenwiping 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
Oct 17 2022