CSSG-Labs / PyNote

Text Editor Written in Python
GNU General Public License v3.0
3 stars 4 forks source link

Updating text.get to end with "end" instead of "end-1c" to avoid needed to add newline #26

Closed PatrickBruso closed 2 years ago

PatrickBruso commented 2 years ago

This code was previously fixed by @mrHeavenli by adding a newline character at the end so that when the txt file is opened in a terminal it properly adds a newline after the last line of text.

t = self.text.get("1.0", "end-1c") + "\n"

I've done some further reading about the text method parameters and it seems like people use "end-1c" to avoid the last character because tkinter always adds a \n to the end of the text.

In light of this, wouldn't it make more sense to change the above code to:

t = self.text.get("1.0", "end")

as that would retain the newline character that is added by Tkinter? Otherwise it seems like we are purposefully not grabbing the newline character by using "end-1c" and then immediately adding it back with "+ \n". I think we should just update the code to use "end" unless someone knows something I don't about why this is wrong.

mrHeavenli commented 2 years ago

Ah, I didn't really do much research, I just tried the editor and decided to slap the "\n" on there because there wasn't one.

In light of this, wouldn't it make more sense to change the above code to: t = self.text.get("1.0", "end")

Yes, it makes a lot more sense!

mrHeavenli commented 2 years ago

I say we should change it to: t = self.text.get("1.0", "end")

PatrickBruso commented 2 years ago

Cool, thanks for the input. I'll let someone take this issue as it's an easy task that can be completed. @andromedamoon-stack maybe you could handle this?

andromedamoon-stack commented 2 years ago

I finished this, but I accidentally pushed it to the main instead of creating a pull request on Github CLI .whoops! So used to the command line in Linux- I need to get familiar with this again. the code seems to work fine locally, let me know if there are any issues I have to change, otherwise I this issue is ok to close

PatrickBruso commented 2 years ago

@andromedamoon-stack looks good. I thought there was an issue but I realized my PR wasn't merged yet and that's why some of my code from earlier was missing. Thanks!