-
Notifications
You must be signed in to change notification settings - Fork 283
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 missing editor/folder specific title vars #1093
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1a17233
refactor title variable handler
amiralies fe9a792
Add activeFolderLong title var
amiralies 240c0c8
Add activeEditorMedium title var
amiralies 1a88a7c
Add activeFolderMedium title vaar
amiralies cab4a3c
Use '~' for base in Path.toRleative
bryphe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,58 +8,81 @@ module Core = Oni_Core; | |
module Model = Oni_Model; | ||
|
||
module Actions = Model.Actions; | ||
module Option = Core.Utility.Option; | ||
module Path = Core.Utility.Path; | ||
|
||
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 withTag = (tag: string, value: option(string)) => | ||
Option.map(v => (tag, v), value); | ||
|
||
let getTemplateVariables: Model.State.t => Core.StringMap.t(string) = | ||
state => { | ||
let initialValues = [("appName", "Onivim 2")]; | ||
|
||
let initialValues = | ||
switch (Model.Selectors.getActiveBuffer(state)) { | ||
| None => initialValues | ||
| Some(buf) => | ||
let fp = Core.Buffer.getFilePath(buf); | ||
let ret = | ||
switch (fp) { | ||
| None => initialValues | ||
| Some(fp) => | ||
let activeEditorShort = Filename.basename(fp); | ||
let parentDir = getDirectory(fp); | ||
|
||
let initialValues = [ | ||
("activeEditorShort", activeEditorShort), | ||
("activeEditorLong", fp), | ||
...initialValues, | ||
]; | ||
|
||
switch (parentDir) { | ||
| None => initialValues | ||
| Some(dir) => [("activeFolderShort", dir), ...initialValues] | ||
}; | ||
}; | ||
switch (Core.Buffer.isModified(buf)) { | ||
| false => ret | ||
| true => [("dirty", "*"), ...ret] | ||
}; | ||
}; | ||
let buffer = Model.Selectors.getActiveBuffer(state); | ||
let filePath = Option.bind(Core.Buffer.getFilePath, buffer); | ||
|
||
let appName = Option.some("Onivim 2") |> withTag("appName"); | ||
|
||
let dirty = | ||
Option.map(Core.Buffer.isModified, buffer) | ||
|> ( | ||
fun | ||
| Some(true) => Some("*") | ||
| _ => None | ||
) | ||
|> withTag("dirty"); | ||
|
||
let initialValues = | ||
let (rootName, rootPath) = | ||
switch (state.workspace) { | ||
| None => initialValues | ||
| Some(workspace) => [ | ||
("rootName", workspace.rootName), | ||
("rootPath", workspace.workingDirectory), | ||
...initialValues, | ||
] | ||
| Some({rootName, workingDirectory}) => ( | ||
Some(rootName) |> withTag("rootName"), | ||
Some(workingDirectory) |> withTag("rootPath"), | ||
) | ||
| None => (None, None) | ||
}; | ||
|
||
initialValues |> List.to_seq |> Core.StringMap.of_seq; | ||
let activeEditorShort = | ||
Option.map(Filename.basename, filePath) |> withTag("activeEditorShort"); | ||
let activeEditorMedium = | ||
filePath | ||
|> Option.bind(fp => | ||
switch (rootPath) { | ||
| Some((_, base)) => Some(Path.toRelative(~base, fp)) | ||
| _ => None | ||
} | ||
) | ||
|> withTag("activeEditorMedium"); | ||
let activeEditorLong = filePath |> withTag("activeEditorLong"); | ||
|
||
let activeFolderShort = | ||
Option.(filePath |> map(Filename.dirname) |> map(Filename.basename)) | ||
|> withTag("activeFolderShort"); | ||
let activeFolderMedium = | ||
filePath | ||
|> Option.map(Filename.dirname) | ||
|> Option.bind(fp => | ||
switch (rootPath) { | ||
| Some((_, base)) => Some(Path.toRelative(~base, fp)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the CI was failing because it expected |
||
| _ => None | ||
} | ||
) | ||
|> withTag("activeFolderMedium"); | ||
let activeFolderLong = | ||
filePath |> Option.map(Filename.dirname) |> withTag("activeFolderLong"); | ||
|
||
[ | ||
appName, | ||
dirty, | ||
activeEditorShort, | ||
activeEditorMedium, | ||
activeEditorLong, | ||
activeFolderShort, | ||
activeFolderMedium, | ||
activeFolderLong, | ||
rootName, | ||
rootPath, | ||
] | ||
|> Option.values | ||
|> List.to_seq | ||
|> Core.StringMap.of_seq; | ||
}; | ||
|
||
module Effects = { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the way you refactored out the
withTag
method and pipe intofun
here - nice! 👍