From ea15ec84280b9946fd7797f1408f03c6756b6a06 Mon Sep 17 00:00:00 2001 From: Bryton Hall Date: Fri, 24 Feb 2023 01:06:03 -0500 Subject: [PATCH] rework directory to be relative to file (#4) --- CHANGELOG.md | 12 ++++++++++++ README.md | 17 +++++++++++++---- package.json | 4 ++-- src/draw.ts | 17 +++++++---------- src/langs.ts | 28 +++++++++++++++++++--------- 5 files changed, 53 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d51f6c..dd584cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +This release reworks the `draw.directory` setting to behave like a more standard filepath. Specifically, it's now relative to the current file (unless the path is absolute). + +To use the previous default behavior of inlining the svg content, set it to `null`. + +To make the path relative to workspace root, use the `workspaceFolder` variable (e.g., `${workspaceFolder}/assets`). + +### Added + +- allow using the `${workspaceFolder}` variable in the `draw.directory` setting + ### Changed +- **BREAKING**: `draw.directory` is now relative to the current file if an absolute path is not given +- **BREAKING**: to save files inline, `draw.directory` now must be `null` instead of an empty string - rename main command title from `Edit Current Line` to `Edit Drawing` for clarity ## [0.1.21] - 2023-02-04 diff --git a/README.md b/README.md index 1d97943..e576c9b 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,19 @@ Consider binding the main command (perhaps to a stylus, if available). For examp The following settings are available (prefixed with `draw`). -| setting | description | default | -| --------- | --------------------------------------------------------------------- | ------- | -| directory | if set, save files to this directory (relative to the workspace root) | `""` | -| buttons | add [custom buttons](#custom-buttons) to the toolbar | `[]` | +| setting | description | default | example | +| ----------- | ---------------------------------------------------- | ------- | --------------------------- | +| `directory` | where to save files | `""` | `${workSpaceFolder}/assets` | +| `buttons` | add [custom buttons](#custom-buttons) to the toolbar | `[]` | _see below_ | + +### directory + +To save contents inline, set `draw.directory` to `null`. + +The following [variables](https://code.visualstudio.com/docs/editor/variables-reference) are currently supported: + + - `workspaceFolder` + ### custom buttons diff --git a/package.json b/package.json index 43ea78f..c5f9bdd 100644 --- a/package.json +++ b/package.json @@ -118,9 +118,9 @@ } }, "draw.directory": { - "type": "string", + "type": ["string", "null"], "default": "", - "description": "Save to directory (write inline if blank)" + "description": "Save to directory (write inline if null)" } } } diff --git a/src/draw.ts b/src/draw.ts index b7e3806..4fb1169 100644 --- a/src/draw.ts +++ b/src/draw.ts @@ -186,7 +186,12 @@ export class Draw { this.target = target; this.setState(); - if (Draw.settings.directory) { + if (target.text.startsWith("