Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add activeEditorShort and activeFolderShort #1001

Merged
merged 2 commits into from
Dec 7, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
};