mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-22 16:08:09 +00:00
Selection is replaced with same text with insertions. Also changed regexps slightly.
This commit is contained in:
parent
85055c39aa
commit
279be3f7e6
1 changed files with 22 additions and 10 deletions
|
@ -73,7 +73,7 @@ QtObject {
|
||||||
function getProjectNameAndRun(str, func) {
|
function getProjectNameAndRun(str, func) {
|
||||||
// We are trying to get the name of the project.
|
// We are trying to get the name of the project.
|
||||||
// To do so, we are getting the substring of a line by using regexp group.
|
// To do so, we are getting the substring of a line by using regexp group.
|
||||||
var projectRegExp = /(#+)[\s*]?(.+)?[\s*]?/i;
|
var projectRegExp = /^(#+)[\s*]?(.+)?[\s*]?$/i;
|
||||||
var isProjectName = projectRegExp.exec(str);
|
var isProjectName = projectRegExp.exec(str);
|
||||||
if (isProjectName) {
|
if (isProjectName) {
|
||||||
var projectName = isProjectName[2];
|
var projectName = isProjectName[2];
|
||||||
|
@ -137,7 +137,7 @@ QtObject {
|
||||||
|
|
||||||
// We are trying to get the task description.
|
// We are trying to get the task description.
|
||||||
// It should be started with either - (minus) or * (asterisk) to indicate list item.
|
// It should be started with either - (minus) or * (asterisk) to indicate list item.
|
||||||
var taskRegExp = /[\*\-][\s*]?(.+)[\s*]?/;
|
var taskRegExp = /^[\*\-][\s*]?(.+)[\s*]?$/;
|
||||||
var taskDescription;
|
var taskDescription;
|
||||||
|
|
||||||
var isTask = taskRegExp.exec(line);
|
var isTask = taskRegExp.exec(line);
|
||||||
|
@ -162,11 +162,16 @@ QtObject {
|
||||||
case "importFromTaskwarrior":
|
case "importFromTaskwarrior":
|
||||||
// Get selected text to determine the project we want to import from.
|
// Get selected text to determine the project we want to import from.
|
||||||
|
|
||||||
|
var plainText = getSelectedTextAndSeparateByNewline();
|
||||||
|
|
||||||
var projectNames = [];
|
var projectNames = [];
|
||||||
|
var projectNameLines = [];
|
||||||
|
var currentLineNo = 0;
|
||||||
var referenceHeaderLevel = 0;
|
var referenceHeaderLevel = 0;
|
||||||
|
|
||||||
getSelectedTextAndSeparateByNewline().forEach(function (line){
|
plainText.forEach(function (line){
|
||||||
if (getProjectNameAndRun(line, function (proName, headerLevel) {
|
currentLineNo++;
|
||||||
|
if (!getProjectNameAndRun(line, function (proName, headerLevel) {
|
||||||
if (projectNames.length === 0) {
|
if (projectNames.length === 0) {
|
||||||
logIfVerbose("No project detected yet. Inserting " + proName)
|
logIfVerbose("No project detected yet. Inserting " + proName)
|
||||||
projectNames.push([proName]);
|
projectNames.push([proName]);
|
||||||
|
@ -193,12 +198,13 @@ QtObject {
|
||||||
logIfVerbose("Project name detected. Inserted value is " + newProjectName.join('.'))
|
logIfVerbose("Project name detected. Inserted value is " + newProjectName.join('.'))
|
||||||
|
|
||||||
})) return;
|
})) return;
|
||||||
|
projectNameLines.push(currentLineNo);
|
||||||
});
|
});
|
||||||
|
|
||||||
// To avoid overwriting what we have selected, we are simply writing it
|
var currentProjectNumber = 0;
|
||||||
script.noteTextEditWrite(script.noteTextEditSelectedText());
|
|
||||||
|
|
||||||
projectNames.forEach( function(projectName) {
|
projectNames.forEach( function(projectName) {
|
||||||
|
currentProjectNumber++;
|
||||||
var concatenatedProjectName = projectName.join('.');
|
var concatenatedProjectName = projectName.join('.');
|
||||||
var result = script.startSynchronousProcess(taskPath,
|
var result = script.startSynchronousProcess(taskPath,
|
||||||
[
|
[
|
||||||
|
@ -216,8 +222,6 @@ QtObject {
|
||||||
return array.join('');
|
return array.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
script.noteTextEditWrite("\n");
|
|
||||||
script.noteTextEditWrite(repeat('#', projectName.length) + ' ' + projectName[projectName.length - 1] + "\n\n");
|
|
||||||
var tasksSeparated;
|
var tasksSeparated;
|
||||||
// The result does not contain any \n, so we are splitting by whitespace.
|
// The result does not contain any \n, so we are splitting by whitespace.
|
||||||
tasksSeparated = result.toString().split('\n');
|
tasksSeparated = result.toString().split('\n');
|
||||||
|
@ -239,7 +243,12 @@ QtObject {
|
||||||
var taskParamsRegexp = /(\d+)[\s*]?(.+)?[\s*]?/i;
|
var taskParamsRegexp = /(\d+)[\s*]?(.+)?[\s*]?/i;
|
||||||
var fetchTaskParams = taskParamsRegexp.exec(task);
|
var fetchTaskParams = taskParamsRegexp.exec(task);
|
||||||
logIfVerbose("Extracted data from task: ID " + fetchTaskParams[1] + " Desc: " + fetchTaskParams[2]);
|
logIfVerbose("Extracted data from task: ID " + fetchTaskParams[1] + " Desc: " + fetchTaskParams[2]);
|
||||||
script.noteTextEditWrite("* " + fetchTaskParams[2] + "\n");
|
var taskEntry = "* " + fetchTaskParams[2];
|
||||||
|
plainText.splice(projectNameLines[currentProjectNumber - 1], 0, taskEntry);
|
||||||
|
var i;
|
||||||
|
for (i = currentProjectNumber; i < projectNameLines.length; i++) {
|
||||||
|
projectNameLines[i] += 1;
|
||||||
|
}
|
||||||
taskIds.push(fetchTaskParams[1]);
|
taskIds.push(fetchTaskParams[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -254,6 +263,9 @@ QtObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
script.noteTextEditWrite(plainText.join('\n'));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue