Skip to content

Commit

Permalink
Add activeEditorShort and activeFolderShort
Browse files Browse the repository at this point in the history
  • Loading branch information
shulhi committed Dec 4, 2019
1 parent a1eeed3 commit 635f26e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Store/TitleStoreConnector.re
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ module Model = Oni_Model;

module Actions = Model.Actions;

let getDirectory = (fp: string): option(string) => {
let dirs =
Filename.dirname(fp) |> String.split_on_char(Filename.dir_sep.[0]);

List.length(dirs) - 1 |> List.nth_opt(dirs);
};

let getTemplateVariables: Model.State.t => Core.StringMap.t(string) =
state => {
let initialValues = [("appName", "Onivim 2")];
Expand All @@ -23,7 +30,18 @@ let getTemplateVariables: Model.State.t => Core.StringMap.t(string) =
| None => initialValues
| Some(fp) =>
let activeEditorShort = Filename.basename(fp);
[("activeEditorShort", activeEditorShort), ...initialValues];
let parentDir = getDirectory(fp);

let initialValues = [
("activeEditorShort", activeEditorShort),
("activeEditorLong", fp),
...initialValues,
];

switch (parentDir) {
| None => initialValues
| Some(dir) => [("activeFolderShort", dir), ...initialValues]
};
};
switch (Model.Buffer.isModified(buf)) {
| false => ret
Expand All @@ -36,6 +54,7 @@ let getTemplateVariables: Model.State.t => Core.StringMap.t(string) =
| None => initialValues
| Some(workspace) => [
("rootName", workspace.rootName),
("rootPath", workspace.workingDirectory),
...initialValues,
]
};
Expand Down Expand Up @@ -85,4 +104,4 @@ let start = setTitle => {
};
};
updater;
};
};

0 comments on commit 635f26e

Please sign in to comment.