Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

First line defaults to title #164

Closed
khaosdoctor opened this issue Mar 29, 2017 · 5 comments
Closed

First line defaults to title #164

khaosdoctor opened this issue Mar 29, 2017 · 5 comments

Comments

@khaosdoctor
Copy link

This is more of a request than a bug. I believe that most of the people don't want to reedit the title of the saved document every first time.

I say this because when you open the editor once and starts a new blank document, upon clicking on save (this is the first save ever for that file), this happens:

Which is the expected behavior, a save dialog.

But what I'm proposing is this:

What if instead of Untitled we could grab the first line of the file, like this:

A simple file with text

Then, upon clicking on save we would have this:

@ayaankazerouni
Copy link
Contributor

I've opened a pull request for this. It's implemented like you've said -- I grab the first suitable line of text and try to form a filename-suggestion out of that. Do you think it would be better to look for the first # header line, rather than simply the first line? Then if I don't find a header line, I could settle for the first line of suitable text.

@khaosdoctor
Copy link
Author

khaosdoctor commented May 21, 2017

This is a really good idea, trying to find the first # Header instead of the first line. More than that. I think this would be the only thing that would make sense, instead of getting the first suitable line, why don't we try to find headers in an descending order, e.g. first the # header headers, than ## header and so on.

@ayaankazerouni
Copy link
Contributor

ayaankazerouni commented May 22, 2017

why don't we try to find headers in an descending order

This could get hairy quickly I think. We would essentially be looping through the whole document for each type of header. Depending on the size of the document, this could be an expensive operation for what is really a very minor usability benefit.

@khaosdoctor
Copy link
Author

No, but we'd stop on the first header. E.g: If there's no first class headers but there's one second class header, then we get the first second class header we can find. If not then a third class header and so on

@brrd
Copy link
Owner

brrd commented May 22, 2017

I think it is a good idea to search for document headers. For example some documents could use YAML headers (#142) which must be ignored.

But no need to parse the document again to find the first header, it is already done in the pane for creating the table of contents. In order to avoid lags which can occur when parsing big documents, we currently do this in a separate thread by using a worker: https://github.com/brrd/Abricotine/blob/develop/app/renderer/abr-pane-worker.js

It is called there: https://github.com/brrd/Abricotine/blob/develop/app/renderer/abr-pane.js#L82

The worker has no access to the DOM, which explains why we can't use CodeMirror methods here.

I think doing this process once is enough. A good solution IMO would be to store the table of contents as a property of abrDocument (so the worker should be run from abrDocument) and to update the pane each time the table of contents changes. Then we could just use the first header in toc when saving.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants