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

Commit

Permalink
Use first line content as default filename (fixes #231)
Browse files Browse the repository at this point in the history
Because return false does't break doc.eachLine() callback
  • Loading branch information
brrd committed Feb 13, 2018
1 parent 9f44154 commit e958d0e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions app/renderer/abr-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ AbrDocument.prototype = {
},

// Functions for title suggestion

getTitleSuggestion: function() {
var filename = /[\w][\w\s-]*/;
var toc = this.toc;
Expand All @@ -375,14 +374,13 @@ AbrDocument.prototype = {

// Check document contents
function getTitleLine() {
var titleLine = '';
doc.eachLine(function(lineHandle) {
if (filename.test(lineHandle.text)) {
titleLine = lineHandle.text;
return false; // break of iterator
}
});
return titleLine;
var firstLine = doc.firstLine();
var lastLine = doc.lastLine();
for (var i=firstLine; i<=lastLine; i++) {
var text = doc.getLine(i);
if (filename.test(text)) return text;
}
return "";
}

// Normalizes the given string
Expand All @@ -405,7 +403,6 @@ AbrDocument.prototype = {
.replace(/\s/g, '_');
return suggestion + ".md";
}

return "";
}

Expand Down

0 comments on commit e958d0e

Please # to comment.