snaptoken / kilo-tutorial

build your own text editor
http://viewsourcecode.org/snaptoken/kilo
825 stars 80 forks source link

Save feature is bugged #58

Open maxxber opened 2 months ago

maxxber commented 2 months ago

Hello, I'm studying the tutorial and I arrived to step 130; I have a big problem with the implementation of saving feature: every time I save a file and reopen it, the first line of text is missing and the rest of the content goes up by one line.

Do you have the same experience? Do you have any ideas of what part of the program needs fixing?

maxxber commented 2 months ago

This is the source code updated at step 130: kilo.txt

maxxber commented 2 months ago

I'm trying to spot if I did a typing mistake, I saw there is a "steps.diff" file with all the code entries: how to use it? steps.txt

It would be ideal if I can obtain the original source code of the tutorial with all the steps reproduced till step 130 and check the differences with my source code...

paigeruten commented 2 months ago

Hi @maxxber, the source code of each step of the tutorial is contained in this repo: https://github.com/snaptoken/kilo-src. The readme shows an example of how to do a diff with your code with whitespace disabled.

You can get to the source code for a specific step from the tutorial by clicking on the step name in the upper-right corner of the diff for that step. Here is the code for step 130: https://github.com/snaptoken/kilo-src/blob/prompt-backspace/kilo.c

Let me know if that helps, and I'm happy to take a closer look at your code a little later if you are still stuck 🙂

maxxber commented 2 months ago

Hello @paigeruten, thank you very much for your explanation, it helped a lot!

I compared the source codes with WinMerge and I saw that I left two portions of code belonging to previous steps:

After removing this couple of code lines the saving function started to work properly! 😊