├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .github
├── FUNDING.yml
├── changelog.hbs
├── dependabot.yml
└── workflows
│ └── release.yml
├── .gitignore
├── .npmrc
├── CHANGELOG.md
├── LICENSE
├── README.md
├── docs
└── attachment
│ └── demo.gif
├── esbuild.config.mjs
├── jest.config.js
├── manifest-beta.json
├── manifest.json
├── package-lock.json
├── package.json
├── src
├── @types
│ └── api.d.ts
├── main.ts
├── taskmarker-Api.ts
├── taskmarker-Plugin.ts
├── taskmarker-Settings.ts
├── taskmarker-SettingsTab.ts
├── taskmarker-TaskMarkModal.ts
└── taskmarker-TaskMarker.ts
├── styles.css
├── tsconfig.json
├── version-bump.mjs
├── version-changelog.mjs
└── versions.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 | [*]
8 |
9 | # Change these settings to your own preference
10 | indent_style = space
11 | indent_size = 4
12 |
13 | # We recommend you to keep these unchanged
14 | end_of_line = lf
15 | charset = utf-8
16 | trim_trailing_whitespace = true
17 | insert_final_newline = true
18 |
19 | [*.md]
20 | trim_trailing_whitespace = false
21 |
22 | [*.{yml,html,rb,css,xml,scss,json}]
23 | indent_size = 2
24 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | npm node_modules
2 | build
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "parser": "@typescript-eslint/parser",
4 | "plugins": [
5 | "@typescript-eslint"
6 | ],
7 | "extends": [
8 | "eslint:recommended",
9 | "plugin:@typescript-eslint/eslint-recommended",
10 | "plugin:@typescript-eslint/recommended"
11 | ],
12 | "parserOptions": {
13 | "sourceType": "module"
14 | },
15 | "rules": {
16 | "no-unused-vars": "off",
17 | // "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
18 | "@typescript-eslint/no-unused-vars": "off",
19 | "@typescript-eslint/no-explicit-any": "off",
20 | "no-useless-escape": "off",
21 | "no-var": "off",
22 | "@typescript-eslint/ban-ts-comment": "off",
23 | "no-prototype-builtins": "off",
24 | "@typescript-eslint/no-empty-function": "off",
25 | "@typescript-eslint/no-this-alias": [
26 | "error",
27 | {
28 | "allowDestructuring": false, // Disallow `const { props, state } = this`; true by default
29 | "allowedNames": ["self"] // Allow `const self = this`; `[]` by default
30 | }
31 | ]
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: wenlzhang # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: f84556 # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12 | polar: # Replace with a single Polar username
13 | buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
14 | thanks_dev: # Replace with a single thanks.dev username
15 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
16 |
--------------------------------------------------------------------------------
/.github/changelog.hbs:
--------------------------------------------------------------------------------
1 | {{#each releases}}
2 | {{#if href}}
3 | ###{{#unless major}}#{{/unless}} [{{title}}]({{href}})
4 | {{else}}
5 | #### {{title}}
6 | {{/if}}
7 |
8 | {{#if tag}}
9 | > {{niceDate}}
10 | {{/if}}
11 |
12 | {{#if summary}}
13 | {{summary}}
14 | {{/if}}
15 |
16 | {{#if fixes}}
17 | Fixes:
18 | {{#each fixes}}
19 | - {{#if commit.breaking}}**Breaking change:** {{/if}}{{commit.subject}} {{#each fixes}}#{{id}} {{/each}}
20 | {{/each}}
21 | {{/if}}
22 |
23 | {{#if commits}}
24 | Commits:
25 | {{#each commits}}
26 | - {{#if breaking}}**Breaking change:** {{/if}}{{subject}}{{#if href}} [`{{shorthash}}`]({{href}}){{/if}}
27 | {{/each}}
28 | {{/if}}
29 |
30 | {{#if merges}}
31 | PRs:
32 | {{#each merges}}
33 | - #{{id}} {{#if commit.breaking}}**Breaking change:** {{/if}}{{message}}
34 | {{/each}}
35 | {{/if}}
36 |
37 | {{/each}}
38 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # To get started with Dependabot version updates, you'll need to specify which
2 | # package ecosystems to update and where the package manifests are located.
3 | # Please see the documentation for all configuration options:
4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: "npm" # See documentation for possible values
9 | directory: "/" # Location of package manifests
10 | schedule:
11 | interval: "weekly"
12 | - package-ecosystem: "github-actions"
13 | directory: "/"
14 | schedule:
15 | interval: "weekly"
16 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 |
3 | on:
4 | push:
5 | tags:
6 | - "[0-9]+.[0-9]+.[0-9]+"
7 |
8 | jobs:
9 | build:
10 | runs-on: ubuntu-latest
11 | permissions:
12 | contents: write
13 | steps:
14 | - uses: actions/checkout@v3
15 | with:
16 | fetch-depth: 0
17 |
18 | - name: Set up Node.js
19 | uses: actions/setup-node@v3
20 | with:
21 | node-version: '18'
22 |
23 | - name: Install dependencies
24 | run: npm ci
25 |
26 | - name: Build
27 | run: npm run build
28 |
29 | - name: Generate Release Notes
30 | id: generate_notes
31 | run: |
32 | # Get the latest tag
33 | LATEST_TAG=$(git describe --tags --abbrev=0)
34 | # Get the previous tag
35 | PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || git rev-list --max-parents=0 HEAD)
36 | # Generate changelog
37 | if [ "$PREVIOUS_TAG" = "$(git rev-list --max-parents=0 HEAD)" ]; then
38 | CHANGELOG=$(git log --pretty=format:"- %s" $PREVIOUS_TAG..$LATEST_TAG)
39 | else
40 | CHANGELOG=$(git log --pretty=format:"- %s" $PREVIOUS_TAG..$LATEST_TAG)
41 | fi
42 | # Save changelog to file
43 | echo "$CHANGELOG" > changelog.md
44 |
45 | - name: Create Release
46 | uses: softprops/action-gh-release@v1
47 | with:
48 | body_path: changelog.md
49 | draft: true
50 | files: |
51 | main.js
52 | manifest.json
53 | styles.css
54 | env:
55 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Intellij
2 | *.iml
3 | .idea
4 |
5 | # VS Code
6 | .vscode
7 |
8 | # npm
9 | node_modules
10 |
11 | # build
12 | build
13 |
14 | # obsidian
15 | data.json
16 |
17 | # buildt
18 | .buildt
19 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | tag-version-prefix=""
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file.
4 |
5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7 |
8 |
9 |
10 |
11 | ## [0.6.2] - 2024-11-27
12 |
13 | ### Changes
14 |
15 | - fix: include required files in GitHub releases
16 | - Update manifest.json
17 | - refactor: simplify release process to use CHANGELOG.md directly
18 |
19 | ## [0.6.1] - 2024-11-27
20 |
21 | ### Changes
22 |
23 | - feat: add GitHub release draft creation to release process
24 |
25 | ## [0.6.0] - 2024-11-27
26 |
27 | ### Changes
28 |
29 | - Update package.json
30 | - Clean up code
31 | - Revert "Update .eslintrc"
32 | - Revert "Update .eslintrc"
33 | - Update .eslintrc
34 | - Update .eslintrc
35 | - Fine tune code
36 | - Update .eslintrc
37 | - Fine tune code
38 | - Prepare release automation
39 | - Update README.md
40 | - Update README.md
41 | - feat: Create newline with previous prefix
42 | - feat: Create newline with previous prefix
43 | - feat: Create newline with previous prefix
44 | - feat: Create newline with previous prefix
45 | - feat: Support operating on none-task or list line
46 | - feat: Support operating on none-task or list line
47 | - feat: Support operating on empty lines
48 | - feat: Support operating on empty lines
49 | - feat: Support operating on empty lines
50 | - feat: Support operating on empty lines
51 | - feat: Support operating on empty lines
52 | - feat: Support operating on empty lines
53 | - feat: Support operating on none-task or list line
54 |
55 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Task Marker
2 |
3 | [](https://github.com/wenlzhang/obsidian-task-marker/releases) 
4 |
5 | An [Obsidian](https://obsidian.md/) plugin to change task status and append text with hotkeys and right-click context menu.
6 |
7 | 
8 |
9 | ## Why You Need Task Marker
10 |
11 | Task management in Obsidian can be challenging when tasks of varying statuses—such as open, completed, or transferred—are scattered throughout extensive notes like meeting summaries. Recognizing this need, we created [Task Marker](https://exp.ptkm.net/obsidian-task-marker), guided by two essential [PTKM Core Principles](https://exp.ptkm.net/ptkm-core-principles):
12 |
13 | - **Task-Centered Workflow**: Prioritizing efficient task management
14 | - **Focus on Important Matters**: Helping users concentrate on what truly matters
15 |
16 | ### The Challenge
17 |
18 | When dealing with lengthy notes filled with numerous list items, key information can easily get lost in the clutter. Consider meeting notes, where ideas, questions, action points, and follow-ups often blend into a single, overwhelming document. Without clear differentiation, finding relevant tasks during reviews becomes time-consuming and error-prone.
19 |
20 | ### The Solution
21 |
22 | **Task Marker** was developed to tackle this challenge head-on by allowing users to assign distinct statuses to tasks directly within their notes. Important items can be marked and highlighted, making it easy to spot critical elements like action points, ideas, questions, pros, and cons at a glance.
23 |
24 | Through intuitive status cycling and customizable hotkeys, you can seamlessly update task states while focusing on what matters most. Moreover, every task status change is timestamped, enabling you to track when tasks were created, completed, or updated.
25 |
26 | Given the importance of accurate time records, we also developed the [[Introducing Timestamp Link|Timestamp Link]] plugin, ensuring time-based task management is built right into your workflow.
27 |
28 | With **Task Marker**, your tasks gain clarity, context, and focus—transforming task management in Obsidian from scattered lists into a streamlined, efficient process.
29 |
30 | ## Documentation
31 |
32 | 📚 **[View Full Documentation](https://exp.ptkm.net/obsidian-task-marker)**
33 |
34 | Visit the documentation site to learn how to make the most of Task Marker in your Obsidian workflow.
35 |
36 | ## Support & Community
37 |
38 | This plugin is a labor of love, developed and maintained during my free time after work and on weekends. A lot of thought, energy, and care goes into making it reliable, user-friendly, and aligned with PTKM principles.
39 |
40 | If you find this plugin valuable in your daily workflow, please consider supporting my work. Your support would mean the world to me and would help me dedicate more time and energy to:
41 |
42 | - Developing new features
43 | - Maintaining code quality
44 | - Providing support and documentation
45 | - Making the plugin even better for everyone
46 |
47 | ### Ways to Support
48 |
49 | You can support this project in several ways:
50 |
51 | - ⭐ Star the project on GitHub
52 | - 💝
53 | - [Sponsor](https://github.com/sponsors/wenlzhang) my work on GitHub
54 | - 💌 Share your success stories and feedback
55 | - 📢 Spread the word about the plugin
56 | - 🐛 [Report issues](https://github.com/wenlzhang/obsidian-task-marker/issues) to help improve the plugin
57 |
58 | Thank you for being part of this journey! 🙏
59 |
--------------------------------------------------------------------------------
/docs/attachment/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wenlzhang/obsidian-task-marker/8a9190040c2b2ad81312109f7e1ef32c58fb9c4b/docs/attachment/demo.gif
--------------------------------------------------------------------------------
/esbuild.config.mjs:
--------------------------------------------------------------------------------
1 | import esbuild from "esbuild";
2 | import process from "process";
3 | import builtins from 'builtin-modules';
4 |
5 | const banner = `/*
6 | THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
7 | if you want to view the source, please visit the github repository of this plugin
8 | */
9 | `;
10 |
11 | const prod = (process.argv[2] === 'production');
12 |
13 | esbuild.build({
14 | banner: {
15 | js: banner,
16 | },
17 | entryPoints: ['src/main.ts'],
18 | bundle: true,
19 | external: ['obsidian', 'electron', ...builtins],
20 | format: 'cjs',
21 | watch: !prod,
22 | target: 'es2016',
23 | logLevel: "info",
24 | sourcemap: prod ? false : 'inline',
25 | treeShaking: true,
26 | outfile: 'build/main.js',
27 | }).catch(() => process.exit(1));
28 |
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | preset: "ts-jest",
3 | testEnvironment: 'jsdom',
4 | moduleDirectories: ['node_modules', 'src', 'test'],
5 | moduleNameMapper: {
6 | "obsidian": "mocks/obsidian.ts"
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/manifest-beta.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "obsidian-task-marker",
3 | "name": "Task Marker",
4 | "version": "0.5.1",
5 | "minAppVersion": "1.0.0",
6 | "description": "Change task statuses with hotkeys and context menu. Complete, cancel and mark tasks, as well as cycle among selected task statuses.",
7 | "author": "wenlzhang",
8 | "authorUrl": "https://github.com/wenlzhang",
9 | "fundingUrl": {
10 | "Buy Me a Coffee": "https://ko-fi.com/f84556"
11 | },
12 | "isDesktopOnly": false
13 | }
14 |
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "id": "obsidian-task-marker",
3 | "name": "Task Marker",
4 | "version": "0.6.2",
5 | "minAppVersion": "1.0.0",
6 | "description": "Change task statuses with hotkeys and context menu. Complete, cancel and mark tasks, as well as cycle among selected task statuses.",
7 | "author": "wenlzhang",
8 | "authorUrl": "https://github.com/wenlzhang",
9 | "fundingUrl": {
10 | "Buy Me a Coffee": "https://ko-fi.com/f84556",
11 | "GitHub Sponsor": "https://github.com/sponsors/wenlzhang"
12 | },
13 | "isDesktopOnly": false
14 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "obsidian-task-marker",
3 | "version": "0.6.2",
4 | "private": true,
5 | "description": "Manage task status in Obsidian (https://obsidian.md)",
6 | "main": "main.js",
7 | "scripts": {
8 | "dev": "node esbuild.config.mjs",
9 | "build": "npm run prettier && node esbuild.config.mjs production && cp manifest.json styles.css build",
10 | "pretest": "eslint --ignore-path .gitignore src/",
11 | "test": "jest --passWithNoTests",
12 | "prettier": "prettier -w 'src/**/*.ts'",
13 | "preversion": "npm run build && npm run test",
14 | "version": "node version-bump.mjs && node version-changelog.mjs && git add manifest.json versions.json CHANGELOG.md && cp manifest.json build/",
15 | "postversion": "git push && git push --tags && gh release create $npm_package_version -F CHANGELOG.md --draft build/main.js manifest.json styles.css"
16 | },
17 | "version-tag-prefix": "",
18 | "keywords": [
19 | "obsidian",
20 | "obsidian-md",
21 | "obsidian-plugin",
22 | "obsidian-md-plugin"
23 | ],
24 | "author": "wenlzhang",
25 | "repository": "github.com:wenlzhang/obsidian-task-marker",
26 | "license": "AGPL-3.0-only",
27 | "devDependencies": {
28 | "@types/jest": "^27.0.2",
29 | "@types/node": "^20.8.10",
30 | "@typescript-eslint/eslint-plugin": "^5.49.0",
31 | "@typescript-eslint/parser": "^5.62.0",
32 | "auto-changelog": "^2.4.0",
33 | "builtin-modules": "^3.3.0",
34 | "esbuild": "^0.19.5",
35 | "eslint": "^8.53.0",
36 | "jest": "^27.2.4",
37 | "moment": "^2.29.4",
38 | "obsidian": "^1.1.1",
39 | "prettier": "^2.8.2",
40 | "ts-jest": "^27.0.5",
41 | "tslib": "^2.6.2",
42 | "typescript": "4.9.4"
43 | },
44 | "auto-changelog": {
45 | "backfillLimit": false,
46 | "commitLimit": false,
47 | "ignoreCommitPattern": "(🔖|🔨|🧹|changelog|release|Update README).*"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/@types/api.d.ts:
--------------------------------------------------------------------------------
1 | export interface API {
2 | /**
3 | * Return completed task values as a string.
4 | * Will be "x", "xX", "x-", or "xX-"
5 | */
6 | getCompletedTaskValues(): string;
7 |
8 | /**
9 | * Return incomplete task values as a string.
10 | * Minimally " ", but could be any other combination of characters, like " >?/123!"
11 | */
12 | getIncompleteTaskValues(): string;
13 |
14 | /**
15 | * Return true if the provided value marks a completed (or canceled) task.
16 | */
17 | isComplete(value: string): boolean;
18 |
19 | /**
20 | * Return true if the provided value marks a canceled task (-).
21 | */
22 | isCanceled(value: string): boolean;
23 |
24 | /**
25 | * Async method that displays a modal menu containing potential task
26 | * completion candidates.
27 | *
28 | * Returns the selected "mark" (character) as a string.
29 | */
30 | getMark(): Promise;
31 | }
32 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { TaskMarkerPlugin } from "./taskmarker-Plugin";
2 |
3 | export default TaskMarkerPlugin;
4 |
--------------------------------------------------------------------------------
/src/taskmarker-Api.ts:
--------------------------------------------------------------------------------
1 | import { App } from "obsidian";
2 | import { API } from "./@types/api";
3 | import { TaskMarker } from "./taskmarker-TaskMarker";
4 | import { promptForMark } from "./taskmarker-TaskMarkModal";
5 |
6 | export class TaskMarkerApi implements API {
7 | app: App;
8 | taskMarker: TaskMarker;
9 |
10 | constructor(app: App, taskMarker: TaskMarker) {
11 | this.app = app;
12 | this.taskMarker = taskMarker;
13 | }
14 |
15 | getCompletedTaskValues(): string {
16 | return this.taskMarker.initSettings.completedTasks;
17 | }
18 |
19 | getIncompleteTaskValues(): string {
20 | return this.taskMarker.settings.incompleteTaskValues;
21 | }
22 |
23 | getMark(): Promise {
24 | return promptForMark(this.app, this.taskMarker);
25 | }
26 |
27 | isComplete(value: string): boolean {
28 | // This may include cancelled tasks (those are still "complete")
29 | return this.getCompletedTaskValues().contains(value);
30 | }
31 | isCanceled(value: string): boolean {
32 | return value === "-";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/taskmarker-Plugin.ts:
--------------------------------------------------------------------------------
1 | import {
2 | addIcon,
3 | Editor,
4 | MarkdownView,
5 | Plugin,
6 | Command,
7 | Menu,
8 | EventRef,
9 | MarkdownPostProcessor,
10 | MarkdownPreviewRenderer,
11 | } from "obsidian";
12 | import { TaskMarker } from "./taskmarker-TaskMarker";
13 | import { DEFAULT_SETTINGS } from "./taskmarker-Settings";
14 | import { TaskMarkerSettingsTab } from "./taskmarker-SettingsTab";
15 | import { promptForMark } from "./taskmarker-TaskMarkModal";
16 | import { API } from "./@types/api";
17 | import { TaskMarkerApi } from "./taskmarker-Api";
18 |
19 | enum Icons {
20 | CREATE = "tm-create-task",
21 | COMPLETE = "tm-complete-task",
22 | CANCEL = "tm-cancel-task",
23 | RESET = "tm-reset-task",
24 | MARK = "tm-mark-task",
25 | CYCLE = "tm-cycle-task",
26 | CYCLE_REVERSELY = "tm-cycle-reversely-task",
27 | COMPLETE_ALL = "tm-complete-all-tasks",
28 | CLEAR = "tm-clear-all-tasks",
29 | MOVE = "tm-move-all-checked-tasks",
30 | }
31 |
32 | export class TaskMarkerPlugin extends Plugin {
33 | taskMarker: TaskMarker;
34 |
35 | /** External-facing plugin API. */
36 | public api: API;
37 |
38 | async onload(): Promise {
39 | console.log("loading Task Marker (TM)");
40 | this.taskMarker = new TaskMarker(this.app);
41 | this.addSettingTab(
42 | new TaskMarkerSettingsTab(this.app, this, this.taskMarker)
43 | );
44 | await this.loadSettings();
45 |
46 | addIcon(
47 | Icons.CREATE,
48 | ''
49 | );
50 | addIcon(
51 | Icons.COMPLETE,
52 | ''
53 | );
54 | addIcon(
55 | Icons.CANCEL,
56 | ''
57 | );
58 | addIcon(
59 | Icons.RESET,
60 | ''
61 | );
62 | addIcon(
63 | Icons.MARK,
64 | ''
65 | );
66 | addIcon(
67 | Icons.CYCLE,
68 | ''
69 | );
70 | addIcon(
71 | Icons.CYCLE_REVERSELY,
72 | ''
73 | );
74 | addIcon(
75 | Icons.COMPLETE_ALL,
76 | ''
77 | );
78 | addIcon(
79 | Icons.CLEAR,
80 | ''
81 | );
82 | // addIcon(
83 | // Icons.MOVE,
84 | // ''
85 | // );
86 |
87 | this.addCommand({
88 | id: "task-marker-create",
89 | name: "Create task",
90 | icon: Icons.CREATE,
91 | editorCallback: (editor: Editor, view: MarkdownView) => {
92 | this.markTaskOnLinesCreate(
93 | " ",
94 | editor,
95 | this.getCurrentLinesFromEditor(editor)
96 | );
97 | },
98 | });
99 |
100 | this.addCommand({
101 | id: "task-marker-create-newline",
102 | name: "Create newline",
103 | icon: Icons.CREATE,
104 | editorCallback: (editor: Editor, view: MarkdownView) => {
105 | this.markTaskOnLinesCreateNewline(
106 | " ",
107 | editor,
108 | this.getCurrentLinesFromEditor(editor)
109 | );
110 | },
111 | });
112 |
113 | this.addCommand({
114 | id: "task-marker-complete",
115 | name: "Complete task",
116 | icon: Icons.COMPLETE,
117 | editorCallback: (editor: Editor, view: MarkdownView) => {
118 | this.markTaskOnLines(
119 | "x",
120 | editor,
121 | this.getCurrentLinesFromEditor(editor)
122 | );
123 | },
124 | });
125 |
126 | this.addCommand({
127 | id: "task-marker-cancel",
128 | name: "Cancel task",
129 | icon: Icons.CANCEL,
130 | editorCheckCallback: (
131 | checking: boolean,
132 | editor: Editor,
133 | view: MarkdownView
134 | ) => {
135 | const value = this.taskMarker.settings.supportCanceledTasks;
136 |
137 | if (value) {
138 | if (!checking) {
139 | this.markTaskOnLines(
140 | "-",
141 | editor,
142 | this.getCurrentLinesFromEditor(editor)
143 | );
144 | }
145 | return true;
146 | }
147 | return false;
148 | },
149 | });
150 |
151 | this.addCommand({
152 | id: "task-marker-mark",
153 | name: "Mark task",
154 | icon: Icons.MARK,
155 | editorCallback: async (editor: Editor, view: MarkdownView) => {
156 | const mark = await promptForMark(this.app, this.taskMarker);
157 | if (mark) {
158 | this.markTaskOnLines(
159 | mark,
160 | editor,
161 | this.getCurrentLinesFromEditor(editor)
162 | );
163 | }
164 | },
165 | });
166 |
167 | this.addCommand({
168 | id: "task-marker-reset",
169 | name: "Reset task",
170 | icon: Icons.RESET,
171 | editorCallback: (editor: Editor, view: MarkdownView) => {
172 | this.markTaskOnLines(
173 | " ",
174 | editor,
175 | this.getCurrentLinesFromEditor(editor)
176 | );
177 | },
178 | });
179 |
180 | this.addCommand({
181 | id: "task-marker-complete-all",
182 | name: "Complete all tasks",
183 | icon: Icons.COMPLETE_ALL,
184 | callback: async () => {
185 | this.completeAllTasks();
186 | },
187 | });
188 |
189 | this.addCommand({
190 | id: "task-marker-reset-all",
191 | name: "Reset all completed tasks",
192 | icon: Icons.CLEAR,
193 | callback: async () => {
194 | this.resetAllTasks();
195 | },
196 | });
197 |
198 | // Set hotkeys for additional task statuses (row 1)
199 | const incompleteTaskValuesLength =
200 | this.taskMarker.settings.incompleteTaskValues.length;
201 |
202 | if (incompleteTaskValuesLength >= 2) {
203 | for (let i = 1; i <= incompleteTaskValuesLength - 1; i++) {
204 | this.addCommand({
205 | id: "task-marker-mark-task-status-row1-" + i.toString(),
206 | name:
207 | "Mark task (row 1) as status " +
208 | i.toString() +
209 | ' "' +
210 | this.taskMarker.settings.incompleteTaskValues[i] +
211 | '"',
212 | icon: Icons.MARK,
213 | editorCallback: (editor: Editor, view: MarkdownView) => {
214 | this.markTaskOnLines(
215 | this.taskMarker.settings.incompleteTaskValues[i],
216 | editor,
217 | this.getCurrentLinesFromEditor(editor)
218 | );
219 | },
220 | });
221 | }
222 | }
223 |
224 | // Set hotkeys for additional task statuses (row 2)
225 | const incompleteTaskValuesRow2Length =
226 | this.taskMarker.settings.incompleteTaskValuesRow2.length;
227 |
228 | if (incompleteTaskValuesRow2Length >= 1) {
229 | for (let i = 0; i <= incompleteTaskValuesRow2Length - 1; i++) {
230 | this.addCommand({
231 | id:
232 | "task-marker-mark-task-status-row2-" +
233 | (i + 1).toString(),
234 | name:
235 | "Mark task (row 2) as status " +
236 | (i + 1).toString() +
237 | ' "' +
238 | this.taskMarker.settings.incompleteTaskValuesRow2[i] +
239 | '"',
240 | icon: Icons.MARK,
241 | editorCallback: (editor: Editor, view: MarkdownView) => {
242 | this.markTaskOnLines(
243 | this.taskMarker.settings.incompleteTaskValuesRow2[
244 | i
245 | ],
246 | editor,
247 | this.getCurrentLinesFromEditor(editor)
248 | );
249 | },
250 | });
251 | }
252 | }
253 |
254 | // Add hotkeys for cycling task statuses
255 | this.addCommand({
256 | id: "task-marker-cycle-task",
257 | name: "Cycle task (main)",
258 | icon: Icons.CYCLE,
259 | editorCallback: (editor: Editor, view: MarkdownView) => {
260 | this.markTaskOnLinesCycle(
261 | "y", // This value does not matter.
262 | editor,
263 | this.getCurrentLinesFromEditor(editor)
264 | );
265 | },
266 | });
267 |
268 | this.addCommand({
269 | id: "task-marker-cycle-task-1",
270 | name: "Cycle task (list 1)",
271 | icon: Icons.CYCLE,
272 | editorCallback: (editor: Editor, view: MarkdownView) => {
273 | this.markTaskOnLinesCycleList1(
274 | "y", // This value does not matter.
275 | editor,
276 | this.getCurrentLinesFromEditor(editor)
277 | );
278 | },
279 | });
280 |
281 | this.addCommand({
282 | id: "task-marker-cycle-task-2",
283 | name: "Cycle task (list 2)",
284 | icon: Icons.CYCLE,
285 | editorCallback: (editor: Editor, view: MarkdownView) => {
286 | this.markTaskOnLinesCycleList2(
287 | "y", // This value does not matter.
288 | editor,
289 | this.getCurrentLinesFromEditor(editor)
290 | );
291 | },
292 | });
293 |
294 | this.addCommand({
295 | id: "task-marker-cycle-task-3",
296 | name: "Cycle task (list 3)",
297 | icon: Icons.CYCLE,
298 | editorCallback: (editor: Editor, view: MarkdownView) => {
299 | this.markTaskOnLinesCycleList3(
300 | "y", // This value does not matter.
301 | editor,
302 | this.getCurrentLinesFromEditor(editor)
303 | );
304 | },
305 | });
306 |
307 | // Add hotkeys for cycling task statuses reversely
308 | this.addCommand({
309 | id: "task-marker-cycle-task-reversely",
310 | name: "Cycle task reversely (main)",
311 | icon: Icons.CYCLE_REVERSELY,
312 | editorCheckCallback: (
313 | checking: boolean,
314 | editor: Editor,
315 | view: MarkdownView
316 | ) => {
317 | const value =
318 | this.taskMarker.settings.supportCyclingTasksReversely;
319 |
320 | if (value) {
321 | if (!checking) {
322 | this.markTaskOnLinesCycleReversely(
323 | "y", // This value does not matter.
324 | editor,
325 | this.getCurrentLinesFromEditor(editor)
326 | );
327 | }
328 | return true;
329 | }
330 | return false;
331 | },
332 | });
333 |
334 | // Add hotkeys for appending text
335 | this.addCommand({
336 | id: "task-marker-append-text",
337 | name: "Append text 1",
338 | // icon: Icons.RESET,
339 | editorCallback: (editor: Editor, view: MarkdownView) => {
340 | this.appendTextOnLines(
341 | "y", // The mark value does not matter.
342 | editor,
343 | this.getCurrentLinesFromEditor(editor)
344 | );
345 | },
346 | });
347 |
348 | this.addCommand({
349 | id: "task-marker-append-text-2",
350 | name: "Append text 2",
351 | // icon: Icons.RESET,
352 | editorCallback: (editor: Editor, view: MarkdownView) => {
353 | this.appendTextOnLinesText2(
354 | "y", // The mark value does not matter.
355 | editor,
356 | this.getCurrentLinesFromEditor(editor)
357 | );
358 | },
359 | });
360 |
361 | this.addCommand({
362 | id: "task-marker-append-text-3",
363 | name: "Append text 3",
364 | // icon: Icons.RESET,
365 | editorCallback: (editor: Editor, view: MarkdownView) => {
366 | this.appendTextOnLinesText3(
367 | "y", // The mark value does not matter.
368 | editor,
369 | this.getCurrentLinesFromEditor(editor)
370 | );
371 | },
372 | });
373 |
374 | this.addCommand({
375 | id: "task-marker-append-text-auto",
376 | name: "Append text automatically",
377 | // icon: Icons.RESET,
378 | editorCheckCallback: (
379 | checking: boolean,
380 | editor: Editor,
381 | view: MarkdownView
382 | ) => {
383 | const value =
384 | this.taskMarker.settings.supportAppendingTextAutomatically;
385 |
386 | if (value) {
387 | if (!checking) {
388 | this.appendTextOnLinesAuto(
389 | "y", // The mark value does not matter.
390 | editor,
391 | this.getCurrentLinesFromEditor(editor)
392 | );
393 | }
394 | return true;
395 | }
396 | return false;
397 | },
398 | });
399 |
400 | this.registerHandlers();
401 | this.api = new TaskMarkerApi(this.app, this.taskMarker);
402 | }
403 |
404 | getCurrentLinesFromEditor(editor: Editor): number[] {
405 | const lines: number[] = [];
406 | if (editor.somethingSelected()) {
407 | const cursorStart = editor.getCursor("from");
408 | const cursorEnd = editor.getCursor("to");
409 | for (let i = cursorStart.line; i <= cursorEnd.line; i++) {
410 | lines.push(i);
411 | }
412 | } else {
413 | const anchor = editor.getCursor("from");
414 | lines.push(anchor.line);
415 | }
416 | return lines;
417 | }
418 |
419 | buildMenu(menu: Menu, editor: any, lines?: number[]): void {
420 | // if right-click create menu item is enabled
421 | if (this.taskMarker.settings.rightClickCreate) {
422 | menu.addItem((item) =>
423 | item
424 | .setTitle("(TM) Create task")
425 | .setIcon(Icons.CREATE)
426 | .onClick(() => {
427 | this.markTaskOnLinesCreate(" ", editor, lines);
428 | })
429 | );
430 | }
431 |
432 | // if right-click create menu item is enabled
433 | if (this.taskMarker.settings.rightClickCreateNewline) {
434 | menu.addItem((item) =>
435 | item
436 | .setTitle("(TM) Create newline")
437 | .setIcon(Icons.CREATE)
438 | .onClick(() => {
439 | this.markTaskOnLinesCreateNewline(" ", editor, lines);
440 | })
441 | );
442 | }
443 |
444 | // if right-click complete menu item is enabled
445 | if (this.taskMarker.settings.rightClickComplete) {
446 | menu.addItem((item) =>
447 | item
448 | .setTitle("(TM) Complete task")
449 | .setIcon(Icons.COMPLETE)
450 | .onClick(() => {
451 | this.markTaskOnLines("x", editor, lines);
452 | })
453 | );
454 |
455 | // if cancelling tasks is supported, add the menu item for that.
456 | if (this.taskMarker.settings.supportCanceledTasks) {
457 | menu.addItem((item) =>
458 | item
459 | .setTitle("(TM) Cancel task")
460 | .setIcon(Icons.CANCEL)
461 | .onClick(() => {
462 | this.markTaskOnLines("-", editor, lines);
463 | })
464 | );
465 | }
466 | }
467 |
468 | // if right-click mark menu item is enabled
469 | if (this.taskMarker.settings.rightClickMark) {
470 | menu.addItem((item) =>
471 | item
472 | .setTitle("(TM) Mark task")
473 | .setIcon(Icons.MARK)
474 | .onClick(async () => {
475 | const mark = await promptForMark(
476 | this.app,
477 | this.taskMarker
478 | );
479 | if (mark) {
480 | this.markTaskOnLines(mark, editor, lines);
481 | }
482 | })
483 | );
484 | }
485 |
486 | // if right-click cycle menu item is enabled
487 | if (this.taskMarker.settings.rightClickCycle) {
488 | menu.addItem((item) =>
489 | item
490 | .setTitle("(TM) Cycle task (main)")
491 | .setIcon(Icons.CYCLE)
492 | .onClick(() => {
493 | this.markTaskOnLinesCycle("y", editor, lines); // The mark value does not matter.
494 | })
495 | );
496 | }
497 | if (this.taskMarker.settings.rightClickCycleList1) {
498 | menu.addItem((item) =>
499 | item
500 | .setTitle("(TM) Cycle task (list 1)")
501 | .setIcon(Icons.CYCLE)
502 | .onClick(() => {
503 | this.markTaskOnLinesCycleList1("y", editor, lines); // The mark value does not matter.
504 | })
505 | );
506 | }
507 | if (this.taskMarker.settings.rightClickCycleList2) {
508 | menu.addItem((item) =>
509 | item
510 | .setTitle("(TM) Cycle task (list 2)")
511 | .setIcon(Icons.CYCLE)
512 | .onClick(() => {
513 | this.markTaskOnLinesCycleList2("y", editor, lines); // The mark value does not matter.
514 | })
515 | );
516 | }
517 | if (this.taskMarker.settings.rightClickCycleList3) {
518 | menu.addItem((item) =>
519 | item
520 | .setTitle("(TM) Cycle task (list 3)")
521 | .setIcon(Icons.CYCLE)
522 | .onClick(() => {
523 | this.markTaskOnLinesCycleList3("y", editor, lines); // The mark value does not matter.
524 | })
525 | );
526 | }
527 |
528 | // if right-click cycle reversely menu item is enabled
529 | if (this.taskMarker.settings.rightClickCycleReversely) {
530 | menu.addItem((item) =>
531 | item
532 | .setTitle("(TM) Cycle task reversely (main)")
533 | .setIcon(Icons.CYCLE_REVERSELY)
534 | .onClick(() => {
535 | this.markTaskOnLinesCycleReversely("y", editor, lines); // The mark value does not matter.
536 | })
537 | );
538 | }
539 |
540 | // add an item for resetting selected tasks if enabled
541 | if (this.taskMarker.settings.rightClickResetTask) {
542 | menu.addItem((item) =>
543 | item
544 | .setTitle("(TM) Reset task")
545 | .setIcon(Icons.RESET)
546 | .onClick(() => {
547 | this.markTaskOnLines(" ", editor, lines);
548 | })
549 | );
550 | }
551 |
552 | // if right-click append menu item is enabled
553 | if (this.taskMarker.settings.rightClickAppend) {
554 | menu.addItem((item) =>
555 | item
556 | .setTitle("(TM) Append text 1")
557 | // .setIcon(Icons.RESET)
558 | .onClick(() => {
559 | this.appendTextOnLines("y", editor, lines); // The mark value does not matter.
560 | })
561 | );
562 | }
563 |
564 | if (this.taskMarker.settings.rightClickAppendText2) {
565 | menu.addItem((item) =>
566 | item
567 | .setTitle("(TM) Append text 2")
568 | // .setIcon(Icons.RESET)
569 | .onClick(() => {
570 | this.appendTextOnLinesText2("y", editor, lines); // The mark value does not matter.
571 | })
572 | );
573 | }
574 |
575 | if (this.taskMarker.settings.rightClickAppendText3) {
576 | menu.addItem((item) =>
577 | item
578 | .setTitle("(TM) Append text 3")
579 | // .setIcon(Icons.RESET)
580 | .onClick(() => {
581 | this.appendTextOnLinesText3("y", editor, lines); // The mark value does not matter.
582 | })
583 | );
584 | }
585 |
586 | if (this.taskMarker.settings.rightClickAppendTextAuto) {
587 | menu.addItem((item) =>
588 | item
589 | .setTitle("(TM) Append text automatically")
590 | // .setIcon(Icons.RESET)
591 | .onClick(() => {
592 | this.appendTextOnLinesAuto("y", editor, lines); // The mark value does not matter.
593 | })
594 | );
595 | }
596 |
597 | // If right-click move completed tasks is enabled:
598 | // if (this.taskMarker.settings.rightClickMove) {
599 | // menu.addItem((item) =>
600 | // item
601 | // .setTitle("(TM) Move completed tasks")
602 | // .setIcon(Icons.MOVE)
603 | // .onClick(async () => {
604 | // this.moveAllTasks();
605 | // })
606 | // );
607 | // }
608 |
609 | // If right-click toggle-all menu item is enabled:
610 | if (this.taskMarker.settings.rightClickToggleAll) {
611 | menu.addItem((item) =>
612 | item
613 | .setTitle("(TM) Complete all tasks")
614 | .setIcon(Icons.COMPLETE_ALL)
615 | .onClick(async () => {
616 | this.completeAllTasks();
617 | })
618 | );
619 | }
620 |
621 | // add an item for resetting selected tasks if enabled
622 | if (this.taskMarker.settings.rightClickResetAll) {
623 | menu.addItem((item) =>
624 | item
625 | .setTitle("(TM) Reset all tasks")
626 | .setIcon(Icons.CLEAR)
627 | .onClick(async () => {
628 | this.resetAllTasks();
629 | })
630 | );
631 | }
632 | }
633 |
634 | async markTaskOnLines(
635 | mark: string,
636 | editor: any,
637 | lines?: number[]
638 | ): Promise {
639 | const activeFile = this.app.workspace.getActiveFile();
640 | const source = await this.app.vault.read(activeFile);
641 |
642 | // Save the cursor position before modifying the file
643 | const cursorPosition = editor.getCursor();
644 | if (!cursorPosition) {
645 | console.error("Failed to get cursor position");
646 | return;
647 | }
648 |
649 | const result = this.taskMarker.markTaskInSource(source, mark, lines);
650 | if (!result || !result.updatedLineText || !result.cursorOffset) {
651 | console.error("Failed to mark task in source");
652 | return;
653 | }
654 |
655 | await this.app.vault.modify(activeFile, result.updatedLineText);
656 |
657 | // Log the values of cursorPosition and result.cursorOffset
658 | if (
659 | !cursorPosition ||
660 | !("line" in cursorPosition && "ch" in cursorPosition) ||
661 | !Array.isArray(result.cursorOffset) ||
662 | result.cursorOffset.length !== 1
663 | ) {
664 | console.error("Invalid cursor position or offset");
665 | return;
666 | }
667 |
668 | // Restore the cursor position after modifying the file
669 | const newCursorPosition = {
670 | line: cursorPosition.line,
671 | ch: cursorPosition.ch + result.cursorOffset[0],
672 | };
673 | editor.setCursor(newCursorPosition);
674 | }
675 |
676 | async markTaskOnLinesCycle(
677 | mark: string,
678 | editor: any,
679 | lines?: number[]
680 | ): Promise {
681 | const activeFile = this.app.workspace.getActiveFile();
682 | const source = await this.app.vault.read(activeFile);
683 |
684 | // Save the cursor position before modifying the file
685 | const cursorPosition = editor.getCursor();
686 | if (!cursorPosition) {
687 | console.error("Failed to get cursor position");
688 | return;
689 | }
690 |
691 | const result = this.taskMarker.markTaskInSourceCycle(
692 | source,
693 | mark,
694 | lines
695 | );
696 | if (!result || !result.updatedLineText || !result.cursorOffset) {
697 | console.error("Failed to mark task in source");
698 | return;
699 | }
700 |
701 | await this.app.vault.modify(activeFile, result.updatedLineText);
702 |
703 | // Log the values of cursorPosition and result.cursorOffset
704 | if (
705 | !cursorPosition ||
706 | !("line" in cursorPosition && "ch" in cursorPosition) ||
707 | !Array.isArray(result.cursorOffset) ||
708 | result.cursorOffset.length !== 1
709 | ) {
710 | console.error("Invalid cursor position or offset");
711 | return;
712 | }
713 |
714 | // Restore the cursor position after modifying the file
715 | const newCursorPosition = {
716 | line: cursorPosition.line,
717 | ch: cursorPosition.ch + result.cursorOffset[0],
718 | };
719 | editor.setCursor(newCursorPosition);
720 | }
721 | async markTaskOnLinesCycleList1(
722 | mark: string,
723 | editor: any,
724 | lines?: number[]
725 | ): Promise {
726 | const activeFile = this.app.workspace.getActiveFile();
727 | const source = await this.app.vault.read(activeFile);
728 |
729 | // Save the cursor position before modifying the file
730 | const cursorPosition = editor.getCursor();
731 | if (!cursorPosition) {
732 | console.error("Failed to get cursor position");
733 | return;
734 | }
735 |
736 | const result = this.taskMarker.markTaskInSourceCycleList1(
737 | source,
738 | mark,
739 | lines
740 | );
741 | if (!result || !result.updatedLineText || !result.cursorOffset) {
742 | console.error("Failed to mark task in source");
743 | return;
744 | }
745 |
746 | await this.app.vault.modify(activeFile, result.updatedLineText);
747 |
748 | // Log the values of cursorPosition and result.cursorOffset
749 | if (
750 | !cursorPosition ||
751 | !("line" in cursorPosition && "ch" in cursorPosition) ||
752 | !Array.isArray(result.cursorOffset) ||
753 | result.cursorOffset.length !== 1
754 | ) {
755 | console.error("Invalid cursor position or offset");
756 | return;
757 | }
758 |
759 | // Restore the cursor position after modifying the file
760 | const newCursorPosition = {
761 | line: cursorPosition.line,
762 | ch: cursorPosition.ch + result.cursorOffset[0],
763 | };
764 | editor.setCursor(newCursorPosition);
765 | }
766 | async markTaskOnLinesCycleList2(
767 | mark: string,
768 | editor: any,
769 | lines?: number[]
770 | ): Promise {
771 | const activeFile = this.app.workspace.getActiveFile();
772 | const source = await this.app.vault.read(activeFile);
773 |
774 | // Save the cursor position before modifying the file
775 | const cursorPosition = editor.getCursor();
776 | if (!cursorPosition) {
777 | console.error("Failed to get cursor position");
778 | return;
779 | }
780 |
781 | const result = this.taskMarker.markTaskInSourceCycleList2(
782 | source,
783 | mark,
784 | lines
785 | );
786 | if (!result || !result.updatedLineText || !result.cursorOffset) {
787 | console.error("Failed to mark task in source");
788 | return;
789 | }
790 |
791 | await this.app.vault.modify(activeFile, result.updatedLineText);
792 |
793 | // Log the values of cursorPosition and result.cursorOffset
794 | if (
795 | !cursorPosition ||
796 | !("line" in cursorPosition && "ch" in cursorPosition) ||
797 | !Array.isArray(result.cursorOffset) ||
798 | result.cursorOffset.length !== 1
799 | ) {
800 | console.error("Invalid cursor position or offset");
801 | return;
802 | }
803 |
804 | // Restore the cursor position after modifying the file
805 | const newCursorPosition = {
806 | line: cursorPosition.line,
807 | ch: cursorPosition.ch + result.cursorOffset[0],
808 | };
809 | editor.setCursor(newCursorPosition);
810 | }
811 | async markTaskOnLinesCycleList3(
812 | mark: string,
813 | editor: any,
814 | lines?: number[]
815 | ): Promise {
816 | const activeFile = this.app.workspace.getActiveFile();
817 | const source = await this.app.vault.read(activeFile);
818 |
819 | // Save the cursor position before modifying the file
820 | const cursorPosition = editor.getCursor();
821 | if (!cursorPosition) {
822 | console.error("Failed to get cursor position");
823 | return;
824 | }
825 |
826 | const result = this.taskMarker.markTaskInSourceCycleList3(
827 | source,
828 | mark,
829 | lines
830 | );
831 | if (!result || !result.updatedLineText || !result.cursorOffset) {
832 | console.error("Failed to mark task in source");
833 | return;
834 | }
835 |
836 | await this.app.vault.modify(activeFile, result.updatedLineText);
837 |
838 | // Log the values of cursorPosition and result.cursorOffset
839 | if (
840 | !cursorPosition ||
841 | !("line" in cursorPosition && "ch" in cursorPosition) ||
842 | !Array.isArray(result.cursorOffset) ||
843 | result.cursorOffset.length !== 1
844 | ) {
845 | console.error("Invalid cursor position or offset");
846 | return;
847 | }
848 |
849 | // Restore the cursor position after modifying the file
850 | const newCursorPosition = {
851 | line: cursorPosition.line,
852 | ch: cursorPosition.ch + result.cursorOffset[0],
853 | };
854 | editor.setCursor(newCursorPosition);
855 | }
856 |
857 | async markTaskOnLinesCycleReversely(
858 | mark: string,
859 | editor: any,
860 | lines?: number[]
861 | ): Promise {
862 | const activeFile = this.app.workspace.getActiveFile();
863 | const source = await this.app.vault.read(activeFile);
864 |
865 | // Save the cursor position before modifying the file
866 | const cursorPosition = editor.getCursor();
867 | if (!cursorPosition) {
868 | console.error("Failed to get cursor position");
869 | return;
870 | }
871 |
872 | const result = this.taskMarker.markTaskInSourceCycleReversely(
873 | source,
874 | mark,
875 | lines
876 | );
877 | if (!result || !result.updatedLineText || !result.cursorOffset) {
878 | console.error("Failed to mark task in source");
879 | return;
880 | }
881 |
882 | await this.app.vault.modify(activeFile, result.updatedLineText);
883 |
884 | // Log the values of cursorPosition and result.cursorOffset
885 | if (
886 | !cursorPosition ||
887 | !("line" in cursorPosition && "ch" in cursorPosition) ||
888 | !Array.isArray(result.cursorOffset) ||
889 | result.cursorOffset.length !== 1
890 | ) {
891 | console.error("Invalid cursor position or offset");
892 | return;
893 | }
894 |
895 | // Restore the cursor position after modifying the file
896 | const newCursorPosition = {
897 | line: cursorPosition.line,
898 | ch: cursorPosition.ch + result.cursorOffset[0],
899 | };
900 | editor.setCursor(newCursorPosition);
901 | }
902 |
903 | async markTaskOnLinesCreate(
904 | mark: string,
905 | editor: any,
906 | lines?: number[]
907 | ): Promise {
908 | const activeFile = this.app.workspace.getActiveFile();
909 | const source = await this.app.vault.read(activeFile);
910 |
911 | // Save the cursor position before modifying the file
912 | const cursorPosition = editor.getCursor();
913 | if (!cursorPosition) {
914 | console.error("Failed to get cursor position");
915 | return;
916 | }
917 |
918 | const result = this.taskMarker.markTaskInSourceCreate(
919 | source,
920 | mark,
921 | lines
922 | );
923 | if (!result || !result.updatedLineText || !result.cursorOffset) {
924 | console.error("Failed to mark task in source");
925 | return;
926 | }
927 |
928 | await this.app.vault.modify(activeFile, result.updatedLineText);
929 |
930 | // Log the values of cursorPosition and result.cursorOffset
931 | if (
932 | !cursorPosition ||
933 | !("line" in cursorPosition && "ch" in cursorPosition) ||
934 | !Array.isArray(result.cursorOffset) ||
935 | result.cursorOffset.length !== 1
936 | ) {
937 | console.error("Invalid cursor position or offset");
938 | return;
939 | }
940 |
941 | // Restore the cursor position after modifying the file
942 | const newCursorPosition = {
943 | line: cursorPosition.line,
944 | ch: cursorPosition.ch + result.cursorOffset[0],
945 | };
946 | editor.setCursor(newCursorPosition);
947 | }
948 |
949 | async markTaskOnLinesCreateNewline(
950 | mark: string,
951 | editor: any,
952 | lines?: number[]
953 | ): Promise {
954 | const activeFile = this.app.workspace.getActiveFile();
955 | const source = await this.app.vault.read(activeFile);
956 |
957 | // Save the cursor position before modifying the file
958 | const cursorPosition = editor.getCursor();
959 | if (!cursorPosition) {
960 | console.error("Failed to get cursor position");
961 | return;
962 | }
963 |
964 | const result = this.taskMarker.markTaskInSourceCreateNewline(
965 | source,
966 | lines,
967 | cursorPosition
968 | );
969 | if (!result || !result.updatedLineText || !result.cursorOffset) {
970 | console.error("Failed to mark task in source");
971 | return;
972 | }
973 |
974 | await this.app.vault.modify(activeFile, result.updatedLineText);
975 |
976 | // Log the values of cursorPosition and result.cursorOffset
977 | if (
978 | !cursorPosition ||
979 | !("line" in cursorPosition && "ch" in cursorPosition) ||
980 | !Array.isArray(result.cursorOffset) ||
981 | result.cursorOffset.length !== 1
982 | ) {
983 | console.error("Invalid cursor position or offset");
984 | return;
985 | }
986 |
987 | // Restore the cursor position after modifying the file
988 | const newCursorPosition = {
989 | line: cursorPosition.line + 1,
990 | ch: result.cursorOffset[0],
991 | };
992 | editor.setCursor(newCursorPosition);
993 | }
994 |
995 | async appendTextOnLines(
996 | mark: string,
997 | editor: any,
998 | lines?: number[]
999 | ): Promise {
1000 | const activeFile = this.app.workspace.getActiveFile();
1001 | const source = await this.app.vault.read(activeFile);
1002 |
1003 | // Save the cursor position before modifying the file
1004 | const cursorPosition = editor.getCursor();
1005 |
1006 | const result = this.taskMarker.appendTextInSource(source, mark, lines);
1007 | await this.app.vault.modify(activeFile, result);
1008 |
1009 | // Restore the cursor position after modifying the file
1010 | editor.setCursor(cursorPosition);
1011 | }
1012 |
1013 | async appendTextOnLinesText2(
1014 | mark: string,
1015 | editor: any,
1016 | lines?: number[]
1017 | ): Promise {
1018 | const activeFile = this.app.workspace.getActiveFile();
1019 | const source = await this.app.vault.read(activeFile);
1020 |
1021 | // Save the cursor position before modifying the file
1022 | const cursorPosition = editor.getCursor();
1023 |
1024 | const result = this.taskMarker.appendTextInSourceText2(
1025 | source,
1026 | mark,
1027 | lines
1028 | );
1029 | await this.app.vault.modify(activeFile, result);
1030 |
1031 | // Restore the cursor position after modifying the file
1032 | editor.setCursor(cursorPosition);
1033 | }
1034 |
1035 | async appendTextOnLinesText3(
1036 | mark: string,
1037 | editor: any,
1038 | lines?: number[]
1039 | ): Promise {
1040 | const activeFile = this.app.workspace.getActiveFile();
1041 | const source = await this.app.vault.read(activeFile);
1042 |
1043 | // Save the cursor position before modifying the file
1044 | const cursorPosition = editor.getCursor();
1045 |
1046 | const result = this.taskMarker.appendTextInSourceText3(
1047 | source,
1048 | mark,
1049 | lines
1050 | );
1051 | await this.app.vault.modify(activeFile, result);
1052 |
1053 | // Restore the cursor position after modifying the file
1054 | editor.setCursor(cursorPosition);
1055 | }
1056 |
1057 | async appendTextOnLinesAuto(
1058 | mark: string,
1059 | editor: any,
1060 | lines?: number[]
1061 | ): Promise {
1062 | const activeFile = this.app.workspace.getActiveFile();
1063 | const source = await this.app.vault.read(activeFile);
1064 |
1065 | // Save the cursor position before modifying the file
1066 | const cursorPosition = editor.getCursor();
1067 |
1068 | const result = this.taskMarker.appendTextInSourceAuto(
1069 | source,
1070 | mark,
1071 | lines
1072 | );
1073 | await this.app.vault.modify(activeFile, result);
1074 |
1075 | // Restore the cursor position after modifying the file
1076 | editor.setCursor(cursorPosition);
1077 | }
1078 |
1079 | // async moveAllTasks(): Promise {
1080 | // const activeFile = this.app.workspace.getActiveFile();
1081 | // const source = await this.app.vault.read(activeFile);
1082 | // const result = this.taskMarker.moveCompletedTasksInFile(source);
1083 | // this.app.vault.modify(activeFile, result);
1084 | // }
1085 |
1086 | async completeAllTasks(): Promise {
1087 | const activeFile = this.app.workspace.getActiveFile();
1088 | const source = await this.app.vault.read(activeFile);
1089 | const result = this.taskMarker.markAllTasksComplete(source, "x");
1090 | this.app.vault.modify(activeFile, result);
1091 | }
1092 |
1093 | async resetAllTasks(): Promise {
1094 | const activeFile = this.app.workspace.getActiveFile();
1095 | const source = await this.app.vault.read(activeFile);
1096 | const result = this.taskMarker.resetAllTasks(source);
1097 | this.app.vault.modify(activeFile, result);
1098 | }
1099 |
1100 | handlersRegistered = false;
1101 | eventRef: EventRef;
1102 | postProcessor: MarkdownPostProcessor;
1103 | registerHandlers(): void {
1104 | if (
1105 | this.taskMarker.initSettings.registerHandlers &&
1106 | !this.handlersRegistered
1107 | ) {
1108 | this.handlersRegistered = true;
1109 |
1110 | // Source / Edit mode
1111 | if (this.taskMarker.initSettings.rightClickTaskMenu) {
1112 | this.registerEvent(
1113 | (this.eventRef = this.app.workspace.on(
1114 | "editor-menu",
1115 | (menu, editor) => {
1116 | //get line selections here
1117 | this.buildMenu(
1118 | menu,
1119 | editor,
1120 | this.getCurrentLinesFromEditor(editor)
1121 | );
1122 | }
1123 | ))
1124 | );
1125 | }
1126 |
1127 | // Preview / Live Preview
1128 | this.registerMarkdownPostProcessor(
1129 | (this.postProcessor = (el, ctx) => {
1130 | const checkboxes = el.querySelectorAll(
1131 | ".task-list-item-checkbox"
1132 | );
1133 | if (!checkboxes.length) return;
1134 |
1135 | const section = ctx.getSectionInfo(el);
1136 | if (!section) return;
1137 |
1138 | const { lineStart } = section;
1139 |
1140 | for (const checkbox of Array.from(checkboxes)) {
1141 | const line = Number(checkbox.dataset.line);
1142 |
1143 | if (this.taskMarker.initSettings.rightClickTaskMenu) {
1144 | this.registerDomEvent(
1145 | checkbox.parentElement,
1146 | "contextmenu",
1147 | (ev) => {
1148 | ev.preventDefault();
1149 | const view =
1150 | this.app.workspace.getActiveViewOfType(
1151 | MarkdownView
1152 | );
1153 | if (view && view.editor) {
1154 | const menu = new Menu();
1155 | this.buildMenu(menu, [
1156 | lineStart + line,
1157 | ]);
1158 | menu.showAtMouseEvent(ev);
1159 | }
1160 | }
1161 | );
1162 | }
1163 |
1164 | if (this.taskMarker.settings.previewOnClick) {
1165 | this.registerDomEvent(
1166 | checkbox,
1167 | "click",
1168 | async (ev) => {
1169 | ev.stopImmediatePropagation();
1170 | ev.preventDefault();
1171 | const mark = await promptForMark(
1172 | this.app,
1173 | this.taskMarker
1174 | );
1175 | if (mark) {
1176 | this.markTaskOnLines(mark, [
1177 | lineStart + line,
1178 | ]);
1179 | }
1180 | }
1181 | );
1182 | }
1183 | }
1184 | })
1185 | );
1186 | }
1187 | }
1188 |
1189 | unregisterHandlers(): void {
1190 | this.handlersRegistered = false;
1191 |
1192 | if (this.eventRef) {
1193 | this.app.workspace.offref(this.eventRef);
1194 | this.eventRef = null;
1195 | }
1196 |
1197 | if (this.postProcessor) {
1198 | MarkdownPreviewRenderer.unregisterPostProcessor(this.postProcessor);
1199 | this.postProcessor = null;
1200 | }
1201 | }
1202 |
1203 | onunload(): void {
1204 | console.log("unloading Task Marker (TM)");
1205 | }
1206 |
1207 | async loadSettings(): Promise {
1208 | const settings = Object.assign(
1209 | {},
1210 | DEFAULT_SETTINGS,
1211 | await this.loadData()
1212 | );
1213 | // remove old attribute
1214 | if (settings.rightClickReset) {
1215 | delete settings.rightClickReset;
1216 | await this.saveData(settings);
1217 | }
1218 | this.taskMarker.updateSettings(settings);
1219 | }
1220 |
1221 | async saveSettings(): Promise {
1222 | await this.saveData(this.taskMarker.settings);
1223 | if (
1224 | this.taskMarker.initSettings.rightClickTaskMenu &&
1225 | !this.handlersRegistered
1226 | ) {
1227 | this.registerHandlers();
1228 | }
1229 | if (
1230 | !this.taskMarker.initSettings.rightClickTaskMenu &&
1231 | this.handlersRegistered
1232 | ) {
1233 | this.unregisterHandlers();
1234 | }
1235 | }
1236 | }
1237 |
--------------------------------------------------------------------------------
/src/taskmarker-Settings.ts:
--------------------------------------------------------------------------------
1 | export interface TaskMarkerSettings {
2 | // completedAreaHeader: string;
3 | supportOperatingOnAnyLineText: boolean;
4 | defaultListTaskPrefix: string;
5 | removeExpression: string;
6 | appendDateFormat: string;
7 | appendTextFormatMark: string;
8 | appendTextFormatMarkRow2: string;
9 | appendTextFormatCreation: string;
10 | appendTextFormatAppend: string;
11 | appendTextFormatAppendText2: string;
12 | appendTextFormatAppendText3: string;
13 | appendRemoveAllTasks: boolean;
14 | incompleteTaskValues: string;
15 | incompleteTaskValuesRow2: string;
16 | cycleTaskValues: string;
17 | cycleTaskValuesList1: string;
18 | cycleTaskValuesList2: string;
19 | cycleTaskValuesList3: string;
20 | supportCanceledTasks: boolean;
21 | supportCyclingTasksReversely: boolean;
22 | supportCyclingWithListItem: boolean;
23 | supportAppendingTextAutomatically: boolean;
24 | appendTextAutoLineDefault: string;
25 | appendTextAutoTaskDefault: string;
26 | previewOnClick: boolean;
27 | rightClickComplete: boolean;
28 | rightClickMark: boolean;
29 | rightClickCycle: boolean;
30 | rightClickCycleList1: boolean;
31 | rightClickCycleList2: boolean;
32 | rightClickCycleList3: boolean;
33 | rightClickCycleReversely: boolean;
34 | rightClickCreate: boolean;
35 | rightClickCreateNewline: boolean;
36 | rightClickAppend: boolean;
37 | rightClickAppendText2: boolean;
38 | rightClickAppendText3: boolean;
39 | rightClickAppendTextAuto: boolean;
40 | // rightClickMove: boolean;
41 | rightClickResetTask: boolean;
42 | rightClickResetAll: boolean;
43 | rightClickToggleAll: boolean;
44 | // completedAreaRemoveCheckbox: boolean;
45 | onlyLowercaseX: boolean;
46 | }
47 |
48 | export const DEFAULT_SETTINGS: TaskMarkerSettings = {
49 | // completedAreaHeader: "## Log",
50 | supportOperatingOnAnyLineText: false,
51 | defaultListTaskPrefix: "none",
52 | removeExpression: "",
53 | appendDateFormat: "",
54 | appendTextFormatMark: "",
55 | appendTextFormatMarkRow2: "",
56 | appendTextFormatCreation: "",
57 | appendTextFormatAppend: "",
58 | appendTextFormatAppendText2: "",
59 | appendTextFormatAppendText3: "",
60 | appendRemoveAllTasks: false,
61 | incompleteTaskValues: " ",
62 | incompleteTaskValuesRow2: "", // For choosing whether to show in the second row
63 | cycleTaskValues: "",
64 | cycleTaskValuesList1: "",
65 | cycleTaskValuesList2: "",
66 | cycleTaskValuesList3: "",
67 | onlyLowercaseX: false,
68 | supportCanceledTasks: true,
69 | supportCyclingTasksReversely: false,
70 | supportCyclingWithListItem: false,
71 | supportAppendingTextAutomatically: false,
72 | appendTextAutoLineDefault: "none",
73 | appendTextAutoTaskDefault: "none",
74 | previewOnClick: false,
75 | rightClickComplete: false,
76 | rightClickMark: false,
77 | rightClickCycle: false,
78 | rightClickCycleList1: false,
79 | rightClickCycleList2: false,
80 | rightClickCycleList3: false,
81 | rightClickCycleReversely: false,
82 | rightClickCreate: false,
83 | rightClickCreateNewline: false,
84 | rightClickAppend: false,
85 | rightClickAppendText2: false,
86 | rightClickAppendText3: false,
87 | rightClickAppendTextAuto: false,
88 | // rightClickMove: false,
89 | rightClickResetTask: false,
90 | rightClickResetAll: false,
91 | rightClickToggleAll: false,
92 | // completedAreaRemoveCheckbox: false,
93 | };
94 | export interface CompiledTasksSettings {
95 | removeRegExp: RegExp;
96 | resetRegExp: RegExp;
97 | incompleteTaskRegExp: RegExp;
98 | incompleteTaskRegExpRow2: RegExp;
99 | // createTaskRegExp: RegExp; // Maybe not needed
100 | rightClickTaskMenu: boolean;
101 | completedTasks: string;
102 | completedTaskRegExp: RegExp;
103 | registerHandlers: boolean;
104 | }
105 |
--------------------------------------------------------------------------------
/src/taskmarker-SettingsTab.ts:
--------------------------------------------------------------------------------
1 | import { App, moment, PluginSettingTab, Setting } from "obsidian";
2 | import {
3 | TaskMarkerSettings,
4 | // DEFAULT_SETTINGS,
5 | } from "./taskmarker-Settings";
6 | import { TaskMarker } from "./taskmarker-TaskMarker";
7 | import TaskMarkerPlugin from "./main";
8 |
9 | export class TaskMarkerSettingsTab extends PluginSettingTab {
10 | plugin: TaskMarkerPlugin;
11 | taskMarker: TaskMarker;
12 |
13 | constructor(app: App, plugin: TaskMarkerPlugin, taskMarker: TaskMarker) {
14 | super(app, plugin);
15 | this.plugin = plugin;
16 | this.taskMarker = taskMarker;
17 | }
18 |
19 | display(): void {
20 | this.containerEl.empty();
21 |
22 | this.containerEl.createEl("h1", { text: "Task Marker" });
23 |
24 | const tempSettings: TaskMarkerSettings = Object.assign(
25 | this.taskMarker.settings
26 | );
27 |
28 | this.containerEl.createEl("h3", {
29 | text: "Please try reopening the vault or restarting Obsidian if the following setting changes do not take effect.",
30 | });
31 |
32 | this.containerEl.createEl("h2", { text: "General" });
33 |
34 | new Setting(this.containerEl)
35 | .setName("Support operating on any line text")
36 | .setDesc(
37 | "Default disabled. If enabled, commands can operate on any line text, i.e., none-list and none-task line texts."
38 | )
39 | .addToggle((toggle) =>
40 | toggle
41 | .setValue(tempSettings.supportOperatingOnAnyLineText)
42 | .onChange(async (value) => {
43 | tempSettings.supportOperatingOnAnyLineText = value;
44 | this.taskMarker.updateSettings(tempSettings);
45 | await this.plugin.saveSettings();
46 | })
47 | );
48 |
49 | new Setting(this.containerEl)
50 | .setName("Set a default prefix for list items/tasks")
51 | .setDesc(
52 | 'For this to take effect, it requires "Support operating on any line text" be enabled.'
53 | )
54 | .addDropdown((dropdown) =>
55 | dropdown
56 | .addOption("none", "None")
57 | .addOption("prefix-1", "-")
58 | .addOption("prefix-2", "*")
59 | .addOption("prefix-3", "+")
60 | .setValue(tempSettings.defaultListTaskPrefix)
61 | .onChange(
62 | async (
63 | value: "none" | "prefix-1" | "prefix-2" | "prefix-3"
64 | ) => {
65 | tempSettings.defaultListTaskPrefix = value;
66 | this.taskMarker.updateSettings(tempSettings);
67 | await this.plugin.saveSettings();
68 | }
69 | )
70 | );
71 |
72 | this.containerEl.createEl("h2", { text: "Create tasks" });
73 |
74 | // this.containerEl.createEl("p", {
75 | // text: "Created tasks gain treatment based on the settings below.",
76 | // });
77 |
78 | new Setting(this.containerEl)
79 | .setName("Append text to created task")
80 | .setDesc(
81 | "Default empty. If set non-empty, append the string of moment.js format to the end of the task text."
82 | )
83 | .addMomentFormat((momentFormat) =>
84 | momentFormat
85 | .setPlaceholder("[📝 ]YYYY-MM-DD")
86 | .setValue(tempSettings.appendTextFormatCreation)
87 | .onChange(async (value) => {
88 | try {
89 | // Try formatting "now" with the specified format string
90 | moment().format(value);
91 | tempSettings.appendTextFormatCreation = value;
92 | this.taskMarker.updateSettings(tempSettings);
93 | await this.plugin.saveSettings();
94 | } catch (e) {
95 | console.log(
96 | `Error parsing specified date format: ${value}`
97 | );
98 | }
99 | })
100 | );
101 |
102 | this.containerEl.appendChild(
103 | createEl("a", {
104 | text: "moment.js documentation.",
105 | href: "https://momentjs.com/docs",
106 | cls: "linkInfo",
107 | })
108 | );
109 |
110 | this.containerEl.createEl("h2", { text: "Complete tasks" });
111 |
112 | // this.containerEl.createEl("p", {
113 | // text: "Completed tasks gain treatment based on the settings below.",
114 | // });
115 |
116 | new Setting(this.containerEl)
117 | .setName("Only support x for completed tasks")
118 | .setDesc(
119 | "Only use 'x' (lower case) to indicate completed tasks (hide X (upper case))."
120 | )
121 | .addToggle((toggle) =>
122 | toggle
123 | .setValue(tempSettings.onlyLowercaseX)
124 | .onChange(async (value) => {
125 | tempSettings.onlyLowercaseX = value;
126 | this.taskMarker.updateSettings(tempSettings);
127 | await this.plugin.saveSettings();
128 | })
129 | );
130 |
131 | new Setting(this.containerEl)
132 | .setName("Support canceled tasks")
133 | .setDesc(
134 | "Use '-' to indicate canceled tasks. Canceled tasks are processed in the same way as completed tasks."
135 | )
136 | .addToggle((toggle) =>
137 | toggle
138 | .setValue(tempSettings.supportCanceledTasks)
139 | .onChange(async (value) => {
140 | tempSettings.supportCanceledTasks = value;
141 | this.taskMarker.updateSettings(tempSettings);
142 | await this.plugin.saveSettings();
143 | })
144 | );
145 |
146 | new Setting(this.containerEl)
147 | .setName("Append text to completed task")
148 | .setDesc(
149 | "Default empty. If set non-empty, append the string of moment.js format to the end of the task text."
150 | )
151 | .addMomentFormat((momentFormat) =>
152 | momentFormat
153 | .setPlaceholder("[✅ ]YYYY-MM-DD")
154 | .setValue(tempSettings.appendDateFormat)
155 | .onChange(async (value) => {
156 | try {
157 | // Try formatting "now" with the specified format string
158 | moment().format(value);
159 | tempSettings.appendDateFormat = value;
160 | this.taskMarker.updateSettings(tempSettings);
161 | await this.plugin.saveSettings();
162 | } catch (e) {
163 | console.log(
164 | `Error parsing specified date format: ${value}`
165 | );
166 | }
167 | })
168 | );
169 |
170 | // new Setting(this.containerEl)
171 | // .setName("Remove text in completed task")
172 | // .setDesc(
173 | // "Text matching this regular expression should be removed from the task text. Be careful! Test your expression first. The global flag, 'g' is used for a per-line match."
174 | // )
175 | // .addText((text) =>
176 | // text
177 | // .setPlaceholder(" #(todo|task)")
178 | // .setValue(tempSettings.removeExpression)
179 | // .onChange(async (value) => {
180 | // try {
181 | // // try compiling the regular expression
182 | // this.taskMarker.tryCreateRemoveRegex(value);
183 |
184 | // tempSettings.removeExpression = value;
185 | // this.taskMarker.updateSettings(tempSettings);
186 | // await this.plugin.saveSettings();
187 | // } catch (e) {
188 | // console.log(
189 | // `Error parsing regular expression for text replacement: ${value}`
190 | // );
191 | // }
192 | // })
193 | // );
194 |
195 | // new Setting(this.containerEl)
196 | // .setName("Apply these settings to all tasks")
197 | // .setDesc(
198 | // "Append and remove text as configured above when marking tasks with anything other than a space (to reset)."
199 | // )
200 | // .addToggle((toggle) =>
201 | // toggle
202 | // .setValue(tempSettings.appendRemoveAllTasks)
203 | // .onChange(async (value) => {
204 | // tempSettings.appendRemoveAllTasks = value;
205 | // this.taskMarker.updateSettings(tempSettings);
206 | // await this.plugin.saveSettings();
207 | // })
208 | // );
209 |
210 | this.containerEl.createEl("h2", { text: "Mark tasks" });
211 |
212 | this.containerEl.createEl("p", {
213 | text: "Note that if a mark contains both in row 1 and row 2, then the mark would work as specified in row 1.",
214 | });
215 |
216 | new Setting(this.containerEl)
217 | .setName("Additional task statuses (row 1)")
218 | .setDesc(
219 | "Specify the set of characters that indicate in-progress or incomplete tasks, e.g. 'i>!?D'. All of them (excluding the first open status) can be assigned with hotkeys."
220 | )
221 | .addText((text) =>
222 | text
223 | .setPlaceholder(">!?")
224 | .setValue(tempSettings.incompleteTaskValues)
225 | .onChange(async (value) => {
226 | if (value.contains("x")) {
227 | console.log(
228 | `Set of characters should not contain the marker for completed tasks (x): ${value}`
229 | );
230 | } else if (
231 | !tempSettings.onlyLowercaseX &&
232 | value.contains("X")
233 | ) {
234 | console.log(
235 | `Set of characters should not contain the marker for completed tasks (X): ${value}`
236 | );
237 | } else if (
238 | tempSettings.supportCanceledTasks &&
239 | value.contains("-")
240 | ) {
241 | console.log(
242 | `Set of characters should not contain the marker for canceled tasks (-): ${value}`
243 | );
244 | } else {
245 | if (!value.contains(" ")) {
246 | // Not working if removed
247 | // make sure space is included
248 | value = " " + value;
249 | }
250 | tempSettings.incompleteTaskValues = value;
251 | this.taskMarker.updateSettings(tempSettings);
252 | await this.plugin.saveSettings();
253 | }
254 | })
255 | );
256 |
257 | new Setting(this.containerEl)
258 | .setName("Append text to marked task (row 1)")
259 | .setDesc(
260 | "Default empty. If set non-empty, append the string of moment.js format to the end of the task text."
261 | )
262 | .addMomentFormat((momentFormat) =>
263 | momentFormat
264 | .setPlaceholder("[❎ ]YYYY-MM-DD")
265 | .setValue(tempSettings.appendTextFormatMark)
266 | .onChange(async (value) => {
267 | try {
268 | // Try formatting "now" with the specified format string
269 | moment().format(value);
270 | tempSettings.appendTextFormatMark = value;
271 | this.taskMarker.updateSettings(tempSettings);
272 | await this.plugin.saveSettings();
273 | } catch (e) {
274 | console.log(
275 | `Error parsing specified date format: ${value}`
276 | );
277 | }
278 | })
279 | );
280 |
281 | new Setting(this.containerEl)
282 | .setName("Additional task statuses (row 2)")
283 | .setDesc(
284 | "Specify the set of characters that indicate task statuses, e.g. 'Rip'. All of them can be assigned with hotkeys."
285 | )
286 | .addText((text) =>
287 | text
288 | .setPlaceholder("Rip")
289 | .setValue(tempSettings.incompleteTaskValuesRow2)
290 | .onChange(async (value) => {
291 | if (value.contains("x")) {
292 | console.log(
293 | `Set of characters should not contain the marker for completed tasks (x): ${value}`
294 | );
295 | } else if (
296 | !tempSettings.onlyLowercaseX &&
297 | value.contains("X")
298 | ) {
299 | console.log(
300 | `Set of characters should not contain the marker for completed tasks (X): ${value}`
301 | );
302 | } else if (
303 | tempSettings.supportCanceledTasks &&
304 | value.contains("-")
305 | ) {
306 | console.log(
307 | `Set of characters should not contain the marker for canceled tasks (-): ${value}`
308 | );
309 | } else {
310 | tempSettings.incompleteTaskValuesRow2 = value;
311 | this.taskMarker.updateSettings(tempSettings);
312 | await this.plugin.saveSettings();
313 | }
314 | })
315 | );
316 |
317 | new Setting(this.containerEl)
318 | .setName("Append text to marked task (row 2)")
319 | .setDesc(
320 | "Default empty. If set non-empty, append the string of moment.js format to the end of the task text."
321 | )
322 | .addMomentFormat((momentFormat) =>
323 | momentFormat
324 | .setPlaceholder("YYYY-MM-DD")
325 | .setValue(tempSettings.appendTextFormatMarkRow2)
326 | .onChange(async (value) => {
327 | try {
328 | // Try formatting "now" with the specified format string
329 | moment().format(value);
330 | tempSettings.appendTextFormatMarkRow2 = value;
331 | this.taskMarker.updateSettings(tempSettings);
332 | await this.plugin.saveSettings();
333 | } catch (e) {
334 | console.log(
335 | `Error parsing specified date format: ${value}`
336 | );
337 | }
338 | })
339 | );
340 |
341 | this.containerEl.createEl("h2", { text: "Cycle tasks" });
342 |
343 | // this.containerEl.createEl("p", {
344 | // text: "Cycled tasks gain treatment based on the settings below.",
345 | // });
346 |
347 | new Setting(this.containerEl)
348 | .setName("Cycled task (main)")
349 | .setDesc(
350 | "Specify a set of characters that indicate any task statuses, e.g. 'x- Rip>'."
351 | )
352 | .addText((text) =>
353 | text
354 | .setPlaceholder("x- Rip")
355 | .setValue(tempSettings.cycleTaskValues)
356 | .onChange(async (value) => {
357 | tempSettings.cycleTaskValues = value;
358 | this.taskMarker.updateSettings(tempSettings);
359 | await this.plugin.saveSettings();
360 | })
361 | );
362 |
363 | new Setting(this.containerEl)
364 | .setName("Support cycling task reversely (main)")
365 | .setDesc(
366 | "Default disabled. If enabled, a command would be added to cycle reversely among the statuses as specified above."
367 | )
368 | .addToggle((toggle) =>
369 | toggle
370 | .setValue(tempSettings.supportCyclingTasksReversely)
371 | .onChange(async (value) => {
372 | tempSettings.supportCyclingTasksReversely = value;
373 | this.taskMarker.updateSettings(tempSettings);
374 | await this.plugin.saveSettings();
375 | })
376 | );
377 |
378 | new Setting(this.containerEl)
379 | .setName("Cycled task (list 1)")
380 | .setDesc(
381 | "Specify an additional list of characters that indicate any task statuses."
382 | )
383 | .addText((text) =>
384 | text
385 | .setPlaceholder("ab")
386 | .setValue(tempSettings.cycleTaskValuesList1)
387 | .onChange(async (value) => {
388 | tempSettings.cycleTaskValuesList1 = value;
389 | this.taskMarker.updateSettings(tempSettings);
390 | await this.plugin.saveSettings();
391 | })
392 | );
393 | new Setting(this.containerEl)
394 | .setName("Cycled task (list 2)")
395 | .setDesc(
396 | "Specify an additional list of characters that indicate any task statuses."
397 | )
398 | .addText((text) =>
399 | text
400 | .setPlaceholder("cd")
401 | .setValue(tempSettings.cycleTaskValuesList2)
402 | .onChange(async (value) => {
403 | tempSettings.cycleTaskValuesList2 = value;
404 | this.taskMarker.updateSettings(tempSettings);
405 | await this.plugin.saveSettings();
406 | })
407 | );
408 | new Setting(this.containerEl)
409 | .setName("Cycled task (list 3)")
410 | .setDesc(
411 | "Specify an additional list of characters that indicate any task statuses."
412 | )
413 | .addText((text) =>
414 | text
415 | .setPlaceholder("ef")
416 | .setValue(tempSettings.cycleTaskValuesList3)
417 | .onChange(async (value) => {
418 | tempSettings.cycleTaskValuesList3 = value;
419 | this.taskMarker.updateSettings(tempSettings);
420 | await this.plugin.saveSettings();
421 | })
422 | );
423 |
424 | new Setting(this.containerEl)
425 | .setName("Support cycling with list item")
426 | .setDesc(
427 | "Default disabled. If enabled, list item would be included as the first cycled status."
428 | )
429 | .addToggle((toggle) =>
430 | toggle
431 | .setValue(tempSettings.supportCyclingWithListItem)
432 | .onChange(async (value) => {
433 | tempSettings.supportCyclingWithListItem = value;
434 | this.taskMarker.updateSettings(tempSettings);
435 | await this.plugin.saveSettings();
436 | })
437 | );
438 |
439 | this.containerEl.createEl("h2", { text: "Append text" });
440 |
441 | // this.containerEl.createEl("p", {
442 | // text: "Appended text gains treatment based on the settings below.",
443 | // });
444 |
445 | new Setting(this.containerEl)
446 | .setName("Append text to any line (text 1)")
447 | .setDesc(
448 | "Default empty. If set non-empty, append the string of moment.js format to the end of the line text."
449 | )
450 | .addMomentFormat((momentFormat) =>
451 | momentFormat
452 | .setPlaceholder("[📝 ]YYYY-MM-DD")
453 | .setValue(tempSettings.appendTextFormatAppend)
454 | .onChange(async (value) => {
455 | try {
456 | // Try formatting "now" with the specified format string
457 | moment().format(value);
458 | tempSettings.appendTextFormatAppend = value;
459 | this.taskMarker.updateSettings(tempSettings);
460 | await this.plugin.saveSettings();
461 | } catch (e) {
462 | console.log(
463 | `Error parsing specified date format: ${value}`
464 | );
465 | }
466 | })
467 | );
468 |
469 | new Setting(this.containerEl)
470 | .setName("Append text to any line (text 2)")
471 | .setDesc(
472 | "Default empty. If set non-empty, append the string of moment.js format to the end of the line text."
473 | )
474 | .addMomentFormat((momentFormat) =>
475 | momentFormat
476 | .setPlaceholder("[✅ ]YYYY-MM-DD")
477 | .setValue(tempSettings.appendTextFormatAppendText2)
478 | .onChange(async (value) => {
479 | try {
480 | // Try formatting "now" with the specified format string
481 | moment().format(value);
482 | tempSettings.appendTextFormatAppendText2 = value;
483 | this.taskMarker.updateSettings(tempSettings);
484 | await this.plugin.saveSettings();
485 | } catch (e) {
486 | console.log(
487 | `Error parsing specified date format: ${value}`
488 | );
489 | }
490 | })
491 | );
492 |
493 | new Setting(this.containerEl)
494 | .setName("Append text to any line (text 3)")
495 | .setDesc(
496 | "Default empty. If set non-empty, append the string of moment.js format to the end of the line text."
497 | )
498 | .addMomentFormat((momentFormat) =>
499 | momentFormat
500 | .setPlaceholder("[❎ ]YYYY-MM-DD")
501 | .setValue(tempSettings.appendTextFormatAppendText3)
502 | .onChange(async (value) => {
503 | try {
504 | // Try formatting "now" with the specified format string
505 | moment().format(value);
506 | tempSettings.appendTextFormatAppendText3 = value;
507 | this.taskMarker.updateSettings(tempSettings);
508 | await this.plugin.saveSettings();
509 | } catch (e) {
510 | console.log(
511 | `Error parsing specified date format: ${value}`
512 | );
513 | }
514 | })
515 | );
516 |
517 | this.containerEl.createEl("h2", { text: "Append text automatically" });
518 |
519 | this.containerEl.createEl("p", {
520 | text: 'The settings below correspond to the command "Append text automatically".',
521 | });
522 |
523 | this.containerEl.appendChild(
524 | createEl("a", {
525 | text: 'See "Setting.md" for details.',
526 | href: "https://github.com/wenlzhang/obsidian-task-marker/blob/main/docs/Setting.md",
527 | cls: "linkInfo",
528 | })
529 | );
530 |
531 | new Setting(this.containerEl)
532 | .setName("Append text to a task automatically")
533 | .setDesc(
534 | "Default false. If set true, automatically append text to tasks according to the current task status."
535 | )
536 | .addToggle((toggle) =>
537 | toggle
538 | .setValue(tempSettings.supportAppendingTextAutomatically)
539 | .onChange(async (value) => {
540 | tempSettings.supportAppendingTextAutomatically = value;
541 | this.taskMarker.updateSettings(tempSettings);
542 | await this.plugin.saveSettings();
543 | })
544 | );
545 |
546 | new Setting(this.containerEl)
547 | .setName(
548 | "Set for a marked task the default text to append automatically"
549 | )
550 | .setDesc(
551 | 'Note that this requires "Append text to a task automatically" be enabled. Default "None".'
552 | )
553 | .addDropdown((dropdown) =>
554 | dropdown
555 | .addOption("none", "None")
556 | .addOption(
557 | "text-rows-1-2",
558 | "Append text according to individual rows"
559 | )
560 | .addOption(
561 | "text-row-string",
562 | "Append text according to the row with string"
563 | )
564 | .addOption(
565 | "text-row-1",
566 | "Append text always according to row 1"
567 | )
568 | .addOption(
569 | "text-row-2",
570 | "Append text always according to row 2"
571 | )
572 | .setValue(tempSettings.appendTextAutoTaskDefault)
573 | .onChange(
574 | async (
575 | value:
576 | | "none"
577 | | "text-rows-1-2"
578 | | "text-row-string"
579 | | "text-row-1"
580 | | "text-row-2"
581 | ) => {
582 | tempSettings.appendTextAutoTaskDefault = value;
583 | this.taskMarker.updateSettings(tempSettings);
584 | await this.plugin.saveSettings();
585 | }
586 | )
587 | );
588 |
589 | new Setting(this.containerEl)
590 | .setName(
591 | "Set for a non-task line the default text to append automatically"
592 | )
593 | .setDesc(
594 | 'Note that this requires "Append text to a task automatically" be enabled. Default "None".'
595 | )
596 | .addDropdown((dropdown) =>
597 | dropdown
598 | .addOption("none", "None")
599 | .addOption("text-1", "Append text to any line (text 1)")
600 | .addOption("text-2", "Append text to any line (text 2)")
601 | .addOption("text-3", "Append text to any line (text 3)")
602 | .setValue(tempSettings.appendTextAutoLineDefault)
603 | .onChange(
604 | async (
605 | value: "none" | "text-1" | "text-2" | "text-3"
606 | ) => {
607 | tempSettings.appendTextAutoLineDefault = value;
608 | this.taskMarker.updateSettings(tempSettings);
609 | await this.plugin.saveSettings();
610 | }
611 | )
612 | );
613 |
614 | // this.containerEl.createEl("h2", { text: "Moving completed tasks" });
615 |
616 | // new Setting(this.containerEl)
617 | // .setName("Completed area header")
618 | // .setDesc(
619 | // `Completed (or canceled) tasks will be inserted under the specified header (most recent at the top). When scanning the document for completed/canceled tasks, the contents from this configured header to the next heading or separator (---) will be ignored. This heading will be created if the command is invoked and the heading does not exist. The default heading is '${DEFAULT_SETTINGS.completedAreaHeader}'.`
620 | // )
621 | // .addText((text) =>
622 | // text
623 | // .setPlaceholder("## Log")
624 | // .setValue(tempSettings.completedAreaHeader)
625 | // .onChange(async (value) => {
626 | // tempSettings.completedAreaHeader = value.trim();
627 | // this.taskMarker.updateSettings(tempSettings);
628 | // await this.plugin.saveSettings();
629 | // })
630 | // );
631 |
632 | // new Setting(this.containerEl)
633 | // .setName("Remove the checkbox from moved tasks")
634 | // .setDesc(
635 | // `Remove the checkbox from completed (or canceled) tasks during the move to the completed area. This transforms tasks into normal list items. Task Marker will not be able to reset these items. They also will not appear in task searches or queries. The default value is: '${DEFAULT_SETTINGS.completedAreaRemoveCheckbox}'.`
636 | // )
637 | // .addToggle((toggle) =>
638 | // toggle
639 | // .setValue(tempSettings.completedAreaRemoveCheckbox)
640 | // .onChange(async (value) => {
641 | // tempSettings.completedAreaRemoveCheckbox = value;
642 | // this.taskMarker.updateSettings(tempSettings);
643 | // await this.plugin.saveSettings();
644 | // })
645 | // );
646 |
647 | this.containerEl.createEl("h2", {
648 | text: "Mark tasks using menu items",
649 | });
650 |
651 | this.containerEl.createEl("p", {
652 | text: "The following settings add right click context menu items for Task Marker commands. The menu items will work on the current line or within the current selection in Editing view.",
653 | });
654 |
655 | // new Setting(this.containerEl)
656 | // .setName(
657 | // "Preview / Live preview: Show the selection menu when a checkbox is clicked"
658 | // )
659 | // .setDesc(
660 | // "Display a panel that allows you to select (with mouse or keyboard) the value to assign when you click the task. The selected value will determine follow-on actions: complete, cancel, or reset."
661 | // )
662 | // .addToggle((toggle) =>
663 | // toggle
664 | // .setValue(tempSettings.previewOnClick)
665 | // .onChange(async (value) => {
666 | // tempSettings.previewOnClick = value;
667 | // this.taskMarker.updateSettings(tempSettings);
668 | // await this.plugin.saveSettings();
669 | // })
670 | // );
671 |
672 | new Setting(this.containerEl)
673 | .setName("Add menu item for creating a task")
674 | .setDesc(
675 | 'This menu item will work in a way as specified in the section "Create tasks".'
676 | )
677 | .addToggle((toggle) =>
678 | toggle
679 | .setValue(tempSettings.rightClickCreate)
680 | .onChange(async (value) => {
681 | tempSettings.rightClickCreate = value;
682 | this.taskMarker.updateSettings(tempSettings);
683 | await this.plugin.saveSettings();
684 | })
685 | );
686 |
687 | new Setting(this.containerEl)
688 | .setName("Add menu item for creating a newline")
689 | .setDesc(
690 | 'This menu item will work in a way as specified in the section "Create tasks".'
691 | )
692 | .addToggle((toggle) =>
693 | toggle
694 | .setValue(tempSettings.rightClickCreateNewline)
695 | .onChange(async (value) => {
696 | tempSettings.rightClickCreateNewline = value;
697 | this.taskMarker.updateSettings(tempSettings);
698 | await this.plugin.saveSettings();
699 | })
700 | );
701 |
702 | new Setting(this.containerEl)
703 | .setName("Add menu item for completing a task")
704 | .setDesc(
705 | 'This menu item will work in a way as specified in the section "Complete tasks".'
706 | )
707 | .addToggle((toggle) =>
708 | toggle
709 | .setValue(tempSettings.rightClickComplete)
710 | .onChange(async (value) => {
711 | tempSettings.rightClickComplete = value;
712 | this.taskMarker.updateSettings(tempSettings);
713 | await this.plugin.saveSettings();
714 | })
715 | );
716 |
717 | new Setting(this.containerEl)
718 | .setName("Add menu item for marking a task")
719 | .setDesc(
720 | 'This menu item will work in a way as specified in the section "Mark tasks".'
721 | )
722 | .addToggle((toggle) =>
723 | toggle
724 | .setValue(tempSettings.rightClickMark)
725 | .onChange(async (value) => {
726 | tempSettings.rightClickMark = value;
727 | this.taskMarker.updateSettings(tempSettings);
728 | await this.plugin.saveSettings();
729 | })
730 | );
731 |
732 | new Setting(this.containerEl)
733 | .setName("Add menu item for cycling a task (main)")
734 | .setDesc(
735 | 'This menu item will work in a way as specified in the section "Cycle tasks".'
736 | )
737 | .addToggle((toggle) =>
738 | toggle
739 | .setValue(tempSettings.rightClickCycle)
740 | .onChange(async (value) => {
741 | tempSettings.rightClickCycle = value;
742 | this.taskMarker.updateSettings(tempSettings);
743 | await this.plugin.saveSettings();
744 | })
745 | );
746 |
747 | new Setting(this.containerEl)
748 | .setName("Add menu item for cycling a task reversely (main)")
749 | .setDesc(
750 | 'This menu item will work in a way as specified in the section "Cycle tasks".'
751 | )
752 | .addToggle((toggle) =>
753 | toggle
754 | .setValue(tempSettings.rightClickCycleReversely)
755 | .onChange(async (value) => {
756 | tempSettings.rightClickCycleReversely = value;
757 | this.taskMarker.updateSettings(tempSettings);
758 | await this.plugin.saveSettings();
759 | })
760 | );
761 |
762 | new Setting(this.containerEl)
763 | .setName("Add menu item for cycling a task (list 1)")
764 | .setDesc(
765 | 'This menu item will work in a way as specified in the section "Cycle tasks".'
766 | )
767 | .addToggle((toggle) =>
768 | toggle
769 | .setValue(tempSettings.rightClickCycleList1)
770 | .onChange(async (value) => {
771 | tempSettings.rightClickCycleList1 = value;
772 | this.taskMarker.updateSettings(tempSettings);
773 | await this.plugin.saveSettings();
774 | })
775 | );
776 | new Setting(this.containerEl)
777 | .setName("Add menu item for cycling a task (list 2)")
778 | .setDesc(
779 | 'This menu item will work in a way as specified in the section "Cycle tasks".'
780 | )
781 | .addToggle((toggle) =>
782 | toggle
783 | .setValue(tempSettings.rightClickCycleList2)
784 | .onChange(async (value) => {
785 | tempSettings.rightClickCycleList2 = value;
786 | this.taskMarker.updateSettings(tempSettings);
787 | await this.plugin.saveSettings();
788 | })
789 | );
790 | new Setting(this.containerEl)
791 | .setName("Add menu item for cycling a task (list 3)")
792 | .setDesc(
793 | 'This menu item will work in a way as specified in the section "Cycle tasks".'
794 | )
795 | .addToggle((toggle) =>
796 | toggle
797 | .setValue(tempSettings.rightClickCycleList3)
798 | .onChange(async (value) => {
799 | tempSettings.rightClickCycleList3 = value;
800 | this.taskMarker.updateSettings(tempSettings);
801 | await this.plugin.saveSettings();
802 | })
803 | );
804 |
805 | new Setting(this.containerEl)
806 | .setName("Add menu item for resetting a task")
807 | .setDesc("The menu item will reset the task.")
808 | .addToggle((toggle) =>
809 | toggle
810 | .setValue(tempSettings.rightClickResetTask)
811 | .onChange(async (value) => {
812 | tempSettings.rightClickResetTask = value;
813 | this.taskMarker.updateSettings(tempSettings);
814 | await this.plugin.saveSettings();
815 | })
816 | );
817 |
818 | new Setting(this.containerEl)
819 | .setName("Add menu item for appending text to a line (text 1)")
820 | .setDesc(
821 | 'This menu item will work in a way as specified in the section "Append text".'
822 | )
823 | .addToggle((toggle) =>
824 | toggle
825 | .setValue(tempSettings.rightClickAppend)
826 | .onChange(async (value) => {
827 | tempSettings.rightClickAppend = value;
828 | this.taskMarker.updateSettings(tempSettings);
829 | await this.plugin.saveSettings();
830 | })
831 | );
832 |
833 | new Setting(this.containerEl)
834 | .setName("Add menu item for appending text to a line (text 2)")
835 | .setDesc(
836 | 'This menu item will work in a way as specified in the section "Append text".'
837 | )
838 | .addToggle((toggle) =>
839 | toggle
840 | .setValue(tempSettings.rightClickAppendText2)
841 | .onChange(async (value) => {
842 | tempSettings.rightClickAppendText2 = value;
843 | this.taskMarker.updateSettings(tempSettings);
844 | await this.plugin.saveSettings();
845 | })
846 | );
847 |
848 | new Setting(this.containerEl)
849 | .setName("Add menu item for appending text to a line (text 3)")
850 | .setDesc(
851 | 'This menu item will work in a way as specified in the section "Append text".'
852 | )
853 | .addToggle((toggle) =>
854 | toggle
855 | .setValue(tempSettings.rightClickAppendText3)
856 | .onChange(async (value) => {
857 | tempSettings.rightClickAppendText3 = value;
858 | this.taskMarker.updateSettings(tempSettings);
859 | await this.plugin.saveSettings();
860 | })
861 | );
862 |
863 | new Setting(this.containerEl)
864 | .setName("Add menu item for appending text automatically")
865 | .setDesc(
866 | 'This menu item will work in a way as specified in the section "Append text automatically".'
867 | )
868 | .addToggle((toggle) =>
869 | toggle
870 | .setValue(tempSettings.rightClickAppendTextAuto)
871 | .onChange(async (value) => {
872 | tempSettings.rightClickAppendTextAuto = value;
873 | this.taskMarker.updateSettings(tempSettings);
874 | await this.plugin.saveSettings();
875 | })
876 | );
877 |
878 | // new Setting(this.containerEl)
879 | // .setName("Add menu item for completing all tasks")
880 | // .setDesc(
881 | // "Add an item to the right-click menu in edit mode to mark all incomplete tasks in the current document complete."
882 | // )
883 | // .addToggle((toggle) =>
884 | // toggle
885 | // .setValue(tempSettings.rightClickToggleAll)
886 | // .onChange(async (value) => {
887 | // tempSettings.rightClickToggleAll = value;
888 | // this.taskMarker.updateSettings(tempSettings);
889 | // await this.plugin.saveSettings();
890 | // })
891 | // );
892 |
893 | // new Setting(this.containerEl)
894 | // .setName("Add menu item for resetting all tasks")
895 | // .setDesc(
896 | // "Add an item to the right-click menu to reset all completed (or canceled) tasks."
897 | // )
898 | // .addToggle((toggle) =>
899 | // toggle
900 | // .setValue(tempSettings.rightClickResetAll)
901 | // .onChange(async (value) => {
902 | // tempSettings.rightClickResetAll = value;
903 | // this.taskMarker.updateSettings(tempSettings);
904 | // await this.plugin.saveSettings();
905 | // })
906 | // );
907 |
908 | // new Setting(this.containerEl)
909 | // .setName("Add menu item for moving all completed tasks")
910 | // .setDesc(
911 | // "Add an item to the right-click menu to move all completed (or canceled) tasks."
912 | // )
913 | // .addToggle((toggle) =>
914 | // toggle
915 | // .setValue(tempSettings.rightClickMove)
916 | // .onChange(async (value) => {
917 | // tempSettings.rightClickMove = value;
918 | // this.taskMarker.updateSettings(tempSettings);
919 | // await this.plugin.saveSettings();
920 | // })
921 | // );
922 | }
923 | }
924 |
--------------------------------------------------------------------------------
/src/taskmarker-TaskMarkModal.ts:
--------------------------------------------------------------------------------
1 | import { App, Modal } from "obsidian";
2 | import { TaskMarker } from "./taskmarker-TaskMarker";
3 |
4 | export function promptForMark(
5 | app: App,
6 | taskMarker: TaskMarker
7 | ): Promise {
8 | return new Promise((resolve) => {
9 | const modal = new TaskMarkModal(app, taskMarker);
10 |
11 | modal.onClose = () => {
12 | resolve(modal.chosenMark);
13 | };
14 |
15 | modal.open();
16 | });
17 | }
18 |
19 | export class TaskMarkModal extends Modal {
20 | taskMarker: TaskMarker;
21 | chosenMark: string;
22 | constructor(app: App, taskMarker: TaskMarker) {
23 | super(app);
24 | this.taskMarker = taskMarker;
25 | this.containerEl.id = "taskmarker-modal";
26 | }
27 |
28 | onOpen(): void {
29 | const selector = this.contentEl.createDiv(
30 | "taskmarker-selector markdown-preview-view"
31 | );
32 |
33 | const completedList = selector.createEl("ul");
34 | completedList.addClass("contains-task-list");
35 | this.addTaskValues(
36 | completedList,
37 | this.taskMarker.initSettings.completedTasks,
38 | true
39 | );
40 |
41 | const list = selector.createEl("ul");
42 | list.addClass("contains-task-list");
43 | this.addTaskValues(
44 | list,
45 | this.taskMarker.settings.incompleteTaskValues,
46 | false
47 | );
48 |
49 | const listRow2 = selector.createEl("ul");
50 | listRow2.addClass("contains-task-list");
51 | this.addTaskValues(
52 | listRow2,
53 | this.taskMarker.settings.incompleteTaskValuesRow2,
54 | false
55 | );
56 |
57 | const footer = selector.createEl("nav");
58 | const esc = footer.createSpan();
59 | esc.innerHTML = "esc to dismiss";
60 | const bksp = footer.createSpan();
61 | bksp.innerHTML = "bksp to remove []";
62 |
63 | const self = this;
64 |
65 | const keyListener = function (event: KeyboardEvent) {
66 | self.chosenMark = event.key;
67 | event.preventDefault();
68 | event.stopImmediatePropagation();
69 | self.close();
70 | };
71 | this.scope.register([], null, keyListener);
72 | this.scope.register(["Shift"], null, keyListener);
73 | }
74 |
75 | addTaskValues(
76 | list: HTMLUListElement,
77 | choices: string,
78 | markComplete: boolean
79 | ): void {
80 | const self = this;
81 | for (const character of choices) {
82 | const li = list.createEl("li", {
83 | cls:
84 | "task-list-item " + (character == " " ? "" : " is-checked"),
85 | attr: {
86 | "data-task": character,
87 | },
88 | });
89 | li.addEventListener("click", function (event) {
90 | self.chosenMark = character;
91 | self.close();
92 | });
93 |
94 | const input = li.createEl("input", {
95 | cls: "task-list-item-checkbox",
96 | attr: {
97 | id: "task-list-item-checkbox-" + character,
98 | type: "checkbox",
99 | style: "pointer-events: none;",
100 | },
101 | });
102 | if (character != " ") {
103 | input.setAttribute("checked", "");
104 | }
105 | li.createEl("span", {
106 | text: character == " " ? "␣" : character,
107 | attr: {
108 | style: "pointer-events: none;",
109 | },
110 | });
111 | }
112 | }
113 |
114 | onClose(): void {
115 | this.contentEl.empty();
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/styles.css:
--------------------------------------------------------------------------------
1 | /* Mark Tasks modal */
2 | #taskmarker-modal .modal-close-button {
3 | display: none;
4 | }
5 | #taskmarker-modal .modal {
6 | padding: 10px;
7 | min-width: 200px;
8 | max-width: 300px;
9 | }
10 | #taskmarker-modal .modal-content {
11 | background-color: var(--background-secondary);
12 | margin-top: 0px;
13 | }
14 | #taskmarker-modal .modal .markdown-preview-view {
15 | padding: 5px;
16 | }
17 | #taskmarker-modal .modal .markdown-preview-view ul {
18 | display: flex;
19 | flex-wrap: wrap;
20 | --gap: 3px;
21 | --square: 45px;
22 | margin: calc(-1 * var(--gap)) calc(1 * var(--gap));
23 | margin-block-start: 0;
24 | margin-block-end: 0;
25 | padding-inline-start: 0;
26 | }
27 | #taskmarker-modal .modal .markdown-preview-view ul > li {
28 | margin: var(--gap);
29 | display: block;
30 | width: var(--square);
31 | height: var(--square);
32 | background-color: var(--background-primary);
33 | border: 1px solid var(--background-modifier-border);
34 | border-radius: 2px;
35 | text-indent: unset;
36 | line-height: var(--square);
37 | text-align: center;
38 | }
39 | #taskmarker-modal .modal .markdown-preview-view ul > li::before {
40 | display: none;
41 | }
42 | #taskmarker-modal .modal .markdown-preview-view ul > li > span {
43 | font-family: var(--font-monospace);
44 | }
45 | #taskmarker-modal .modal .markdown-preview-view ul > li.task-list-item .task-list-item-checkbox {
46 | margin-right: 4px;
47 | margin-left: unset;
48 | }
49 | #taskmarker-modal .modal .markdown-preview-view nav {
50 | display: flex;
51 | flex-wrap: wrap;
52 | justify-content: space-around;
53 | }
54 | #taskmarker-modal .modal .markdown-preview-view nav span {
55 | display: block;
56 | font-size: .8em;
57 | color: var(--text-muted);
58 | }
59 |
60 | /* Miscellaneous */
61 | .linkInfo {
62 | font-size: small;
63 | }
64 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "baseUrl": ".",
4 | "inlineSourceMap": true,
5 | "inlineSources": true,
6 | "module": "ESNext",
7 | "target": "es6",
8 | "allowJs": true,
9 | "noImplicitAny": true,
10 | "moduleResolution": "node",
11 | "importHelpers": true,
12 | "lib": [
13 | "dom",
14 | "es5",
15 | "scripthost",
16 | "es2015"
17 | ]
18 | },
19 | "include": [
20 | "**/*.ts"
21 | ]
22 | }
23 |
--------------------------------------------------------------------------------
/version-bump.mjs:
--------------------------------------------------------------------------------
1 | import { readFileSync, writeFileSync } from "fs";
2 |
3 | const targetVersion = process.env.npm_package_version;
4 |
5 | // read minAppVersion from manifest.json and bump version to target version
6 | let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
7 | const { minAppVersion } = manifest;
8 | manifest.version = targetVersion;
9 | writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
10 |
11 | // update versions.json with target version and minAppVersion from manifest.json
12 | let versions = JSON.parse(readFileSync("versions.json", "utf8"));
13 | versions[targetVersion] = minAppVersion;
14 | writeFileSync("versions.json", JSON.stringify(versions, null, "\t"));
15 |
--------------------------------------------------------------------------------
/version-changelog.mjs:
--------------------------------------------------------------------------------
1 | import { readFileSync, writeFileSync } from 'fs';
2 | import { execSync } from 'child_process';
3 |
4 | // Get the new version from package.json
5 | const packageJson = JSON.parse(readFileSync('./package.json', 'utf8'));
6 | const newVersion = packageJson.version;
7 | const date = new Date().toISOString().split('T')[0];
8 |
9 | // Read the current changelog
10 | let changelog = readFileSync('./CHANGELOG.md', 'utf8');
11 |
12 | // Get commit messages since last tag
13 | const getCommitsSinceLastTag = () => {
14 | try {
15 | const lastTag = execSync('git describe --tags --abbrev=0', { encoding: 'utf8' }).trim();
16 | return execSync(`git log ${lastTag}..HEAD --pretty=format:"- %s"`, { encoding: 'utf8' });
17 | } catch (e) {
18 | // If no tags exist, get all commits
19 | return execSync('git log --pretty=format:"- %s"', { encoding: 'utf8' });
20 | }
21 | };
22 |
23 | const commitMessages = getCommitsSinceLastTag();
24 |
25 | // Create new version section with proper spacing
26 | const newSection = `
27 |
28 | ## [${newVersion}] - ${date}
29 |
30 | ### Changes
31 |
32 | ${commitMessages}
33 | `;
34 |
35 | // Insert new section after the header
36 | const headerEnd = changelog.indexOf('\n## ');
37 | changelog = changelog.slice(0, headerEnd) + newSection + changelog.slice(headerEnd);
38 |
39 | // Write back to CHANGELOG.md
40 | writeFileSync('./CHANGELOG.md', changelog);
41 |
42 | // Stage the changelog
43 | execSync('git add CHANGELOG.md');
44 |
--------------------------------------------------------------------------------
/versions.json:
--------------------------------------------------------------------------------
1 | {
2 | "0.1.0": "1.0.0",
3 | "0.6.0": "1.0.0",
4 | "0.6.1": "1.0.0",
5 | "0.6.2": "1.0.0"
6 | }
--------------------------------------------------------------------------------