├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .npmrc ├── .prettierrc ├── .vscode └── settings.json ├── DEV.md ├── LICENSE ├── README.md ├── esbuild.config.mjs ├── jest.config.js ├── manifest.json ├── package-lock.json ├── package.json ├── src ├── controllers │ └── viewController.ts ├── icons.ts ├── main.ts ├── model │ └── suggestion.ts ├── services │ ├── indexingService.test.ts │ ├── indexingService.ts │ ├── loggingService.ts │ ├── settingsService.ts │ ├── suggestionsService.ts │ ├── tokenizationService.test.ts │ ├── tokenizationService.ts │ ├── utilsService.test.ts │ └── utilsService.ts ├── settings.ts └── view │ ├── tree │ ├── tree.ts │ ├── treeNode.ts │ └── treeUpdater.ts │ └── view.ts ├── styles.css ├── tsconfig.json ├── version-bump.mjs └── versions.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | tab_width = 2 11 | max_line_length = 120 12 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | npm node_modules 2 | build -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "env": { "node": true }, 5 | "plugins": [ 6 | "@typescript-eslint" 7 | ], 8 | "extends": [ 9 | "eslint:recommended", 10 | "plugin:@typescript-eslint/eslint-recommended", 11 | "plugin:@typescript-eslint/recommended" 12 | ], 13 | "parserOptions": { 14 | "sourceType": "module" 15 | }, 16 | "rules": { 17 | "no-unused-vars": "off", 18 | "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], 19 | "@typescript-eslint/ban-ts-comment": "off", 20 | "no-prototype-builtins": "off", 21 | "@typescript-eslint/no-empty-function": "off", 22 | "lines-between-class-members": [ "error", "always", { "exceptAfterSingleLine": true }] 23 | } 24 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: 'Bug: ' 5 | labels: triage 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Plugin Version [e.g. 1.2.0] 29 | - Obsidian Version [e.g. 1.1.1] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: 'CR: ' 5 | labels: triage 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # vscode 2 | .vscode 3 | 4 | # Intellij 5 | *.iml 6 | .idea 7 | 8 | # npm 9 | node_modules 10 | 11 | # Don't include the compiled main.js file in the repo. 12 | # They should be uploaded to GitHub releases instead. 13 | main.js 14 | 15 | # Exclude sourcemaps 16 | *.map 17 | 18 | # obsidian 19 | data.json 20 | 21 | # Exclude macOS Finder (System Explorer) View States 22 | .DS_Store 23 | 24 | # Dump files 25 | *.dump.* -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | tag-version-prefix="" -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "tabWidth": 2, 4 | "useTabs": false 5 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.codeActionsOnSave": { 3 | "source.organizeImports": true 4 | }, 5 | "editor.formatOnSave": true, 6 | "editor.tabSize": 2 7 | } -------------------------------------------------------------------------------- /DEV.md: -------------------------------------------------------------------------------- 1 | # Dev Notes 2 | 3 | ## Releasing new releases 4 | 5 | - Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release. 6 | - Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible. 7 | - Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases 8 | - Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release. 9 | - Publish the release. 10 | 11 | > You can simplify the version bump process by running `npm version patch`, `npm version minor` or `npm version major` after updating `minAppVersion` manually in `manifest.json`. 12 | > The command will bump version in `manifest.json` and `package.json`, and add the entry for the new version to `versions.json` 13 | 14 | ## Adding to the community plugin list 15 | 16 | - Check https://github.com/obsidianmd/obsidian-releases/blob/master/plugin-review.md 17 | - Publish an initial version. 18 | - Make sure you have a `README.md` file in the root of your repo. 19 | - Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin. 20 | 21 | ## API Documentation 22 | 23 | See https://github.com/obsidianmd/obsidian-api 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 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 General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🏹 Crossbow 2 | 3 | ![image](https://user-images.githubusercontent.com/38029550/229279990-f10723bc-380e-4e29-b4f2-47f9b8a5beb9.png) 4 | 5 | Crossbow is a plugin for [Obsidian](https://obsidian.md). 6 | 7 | Boost your Obsidian note-taking workflow with this plugin that offers handy suggestions for links to headings, tags, and files, helping you effortlessly weave a web of interconnected notes and supercharge your note graph. 8 | 9 | ## How to use 10 | 11 | Just open the crossbow sidebar by clicking on the crossbow icon in the ribbon. All the suggestions will appear within the sidebar. 12 | 13 | ### Applying suggestions 14 | 15 | Clicking on a suggestion in the sidebar will show you a list of occurrences of the word in the current note. 16 | Clicking on one of the occurences will scroll to it and show you a list of matched cache items that you can link to. These matches are ranked, based on the quality of the match. 17 | 18 | You can apply a match by clicking the appropriate icon next to the match: 19 | 20 | ![image](https://user-images.githubusercontent.com/38029550/236627426-d4d44d7d-f8e4-4d0d-b291-9ec6aa281ee6.png) 21 | 22 | which will insert the following link: 23 | 24 | ![image](https://user-images.githubusercontent.com/38029550/229280048-fe7a8e31-8cbf-4090-a7f0-4bf0b83814d7.png) 25 | 26 | > In Obsidian a pipe (`|`) inside a link denotes the "display text" of the link. This means that the text after the pipe will be shown instead of the link. 27 | 28 | ### Temporarily disabling suggestions 29 | 30 | You can temporarily disable suggestions by righ-clicking the crossbow icon of the crossbow view and selecting "Close". This will close the sidebar and disable suggestions. To re-enable suggestions, just click the crossbow icon in the ribbon again. 31 | 32 | ## Under the hood 33 | 34 | ### What is a suggestion? 35 | 36 | A suggestion is a word in your active editor (current note) that can be linked to a **heading**, a **tag**, or a **file** in your vault: 37 | 38 | ```mermaid 39 | mindmap 40 | root((Suggestion)) 41 | Word in your current note 42 | Obsidian Vault Cache Item 43 | Heading 44 | File 45 | Tag 46 | ``` 47 | 48 | Crossbow leverages Obsidian's internal cache and does not manually parse your vault. 49 | To find matches in your current note, it strips the active editors content of any markdown syntax and then searches for suggestion in the stripped content. 50 | 51 | ### A word about how suggestions are matched 52 | 53 | Crossbow is opinionated, but also configurable about how it creates suggestions. 54 | As of 1.1.1 the process of filtering looks like this: 55 | 56 | Initially, it gathers all the **word**s in the active editor (current note) and all the cache items (Identified by their **cache key**) in the vault. 57 | Then, it follows a simple process for each **word** and **cache key** to create a suggestion: 58 | 59 | ```mermaid 60 | graph TD 61 | START((Start)) 62 | Q_ACT_EDITOR["1. Cache key stems from active editor?
Configurable, see setting Make suggestions to items in the same file"] 63 | Q_EXCT_MATCH["2. Exact match (case sensitive) between word and cache key?"] 64 | Q_WORD_SHORT["3. Word is too short? (Currently fixed to 3 chars)"] 65 | Q_CKEY_SHORT["4. Cache key is too short?
Configurable, see setting Minimum word length of suggestions"] 66 | Q_IS_SUBSTRG["5. Word is a substring of cache key or vice versa?"] 67 | Q_WORD_UCASE["6. Word starts with an uppercase letter?
Configurable, see setting Ignore occurrences which start with a lowercase letter"] 68 | Q_CKEY_UCASE["7. Cache key starts with an uppercase letter?
Configurable, see setting Ignore suggestions which start with a lowercase letter"] 69 | Q_MATCH_INSV["8. Exact match (case insensitive) between word and cache key?"] 70 | Q_LEN_SIMILR["9. Similarity of less than 20% length-wise between word and cache key?"] 71 | 72 | STOP((STOP)) 73 | 74 | SUCCESS_1["Add as very good suggestion (🏆)"] 75 | SUCCESS_2["Add as good suggestion (🥇)"] 76 | SUCCESS_3["Add as mediocre suggestion (🥈)"] 77 | SUCCESS_4["Add as 'not-very-good' suggestion (🥉)"] 78 | 79 | 80 | START --> Q_ACT_EDITOR 81 | 82 | Q_ACT_EDITOR -- Yes --> STOP 83 | Q_ACT_EDITOR -- No --> Q_EXCT_MATCH 84 | 85 | Q_EXCT_MATCH -- Yes --> SUCCESS_1 --> STOP 86 | Q_EXCT_MATCH -- No --> Q_WORD_SHORT 87 | 88 | Q_WORD_SHORT -- Yes --> STOP 89 | Q_WORD_SHORT -- No --> Q_CKEY_SHORT 90 | 91 | Q_CKEY_SHORT -- Yes --> STOP 92 | Q_CKEY_SHORT -- No --> Q_IS_SUBSTRG 93 | 94 | Q_IS_SUBSTRG -- Yes --> STOP 95 | Q_IS_SUBSTRG -- No --> Q_WORD_UCASE 96 | 97 | Q_WORD_UCASE -- Yes --> STOP 98 | Q_WORD_UCASE -- No --> Q_CKEY_UCASE 99 | 100 | Q_CKEY_UCASE -- Yes --> STOP 101 | Q_CKEY_UCASE -- No --> Q_MATCH_INSV 102 | 103 | Q_MATCH_INSV -- Yes --> SUCCESS_2 --> STOP 104 | Q_MATCH_INSV -- No --> Q_LEN_SIMILR 105 | Q_LEN_SIMILR -- Yes --> SUCCESS_4 --> STOP 106 | Q_LEN_SIMILR -- No --> SUCCESS_3 --> STOP 107 | ``` 108 | 109 | Then, suggestions which match the ignored words are removed: 110 | 111 | ```mermaid 112 | graph TD 113 | START((START)) 114 | FE["For each result"] 115 | Q_WORD_IGNOR["Remove if Word is on ignore list (case sensitive)
Configurable, see setting Ignored words"] 116 | STOP((STOP)) 117 | 118 | START --> FE 119 | FE --> Q_WORD_IGNOR 120 | Q_WORD_IGNOR --> FE 121 | Q_WORD_IGNOR --> STOP 122 | ``` 123 | 124 | Keep in mind that these steps are processed in order. For example, take a look at the length filter in step 9. At this point, the **word** and **cache key** are already a substring of each other (step 5), meaning that this step adds things like "donut" and "donut hole punching machine manual". Not things that are in general vastly different to each other, which would create a lot of false positives. 125 | 126 | ## How to install manually 127 | 128 | 1. Clone this repo. 129 | 2. `npm i` or `yarn` to install dependencies 130 | 3. `npm run build` to build crossbow. 131 | 4. Copy `main.js`, `styles.css`, `manifest.json` into a folder called `crossbow` in your vault's `.obsidian/plugins/` folder. 132 | 133 |
134 | If you like this plugin, please consider: 135 |
136 |
137 | 138 | -------------------------------------------------------------------------------- /esbuild.config.mjs: -------------------------------------------------------------------------------- 1 | import esbuild from "esbuild"; 2 | import process from "process"; 3 | import builtins from 'builtin-modules' 4 | 5 | const banner = 6 | `/* 7 | THIS IS A GENERATED/BUNDLED FILE BY ESBUILD 8 | if you want to view the source, please visit the github repository of this plugin 9 | */ 10 | `; 11 | 12 | const prod = (process.argv[2] === 'production'); 13 | 14 | esbuild.build({ 15 | banner: { 16 | js: banner, 17 | }, 18 | entryPoints: ['src/main.ts'], 19 | bundle: true, 20 | external: [ 21 | 'obsidian', 22 | 'electron', 23 | '@codemirror/autocomplete', 24 | '@codemirror/collab', 25 | '@codemirror/commands', 26 | '@codemirror/language', 27 | '@codemirror/lint', 28 | '@codemirror/search', 29 | '@codemirror/state', 30 | '@codemirror/view', 31 | '@lezer/common', 32 | '@lezer/highlight', 33 | '@lezer/lr', 34 | ...builtins], 35 | format: 'cjs', 36 | watch: !prod, 37 | target: 'es2018', 38 | logLevel: "info", 39 | sourcemap: prod ? false : 'inline', 40 | treeShaking: true, 41 | outfile: './main.js', 42 | }).catch(() => process.exit(1)); 43 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | transform: { 3 | '^.+\\.tsx?$': 'ts-jest', 4 | }, 5 | moduleNameMapper: { 6 | '^~/(.*)': '/src/$1', 7 | }, 8 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], 9 | testRegex: '(/(tests|src)/.*.(test|spec))\\.(ts|js)x?$', 10 | coverageDirectory: 'coverage', 11 | collectCoverageFrom: ['src/**/*.test.{ts,tsx,js,jsx}', '!src/**/*.d.ts'], 12 | }; -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "crossbow", 3 | "name": "Crossbow", 4 | "version": "1.4.0", 5 | "minAppVersion": "1.4.11", 6 | "description": "Find possible backlinks in your notes.", 7 | "author": "shoedler", 8 | "authorUrl": "https://github.com/shoedler", 9 | "isDesktopOnly": false 10 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crossbow", 3 | "version": "1.4.0", 4 | "description": "Obsidian plugin to find possible backlinks in your notes (https://obsidian.md)", 5 | "main": "main.js", 6 | "scripts": { 7 | "dev": "node esbuild.config.mjs", 8 | "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", 9 | "version": "node version-bump.mjs && git add manifest.json versions.json", 10 | "test": "jest --passWithNoTests --verbose", 11 | "test-watch": "jest --watch" 12 | }, 13 | "keywords": [], 14 | "author": "shoedler", 15 | "license": "gplv3", 16 | "devDependencies": { 17 | "@types/jest": "^29.5.1", 18 | "@types/node": "^16.11.6", 19 | "@typescript-eslint/eslint-plugin": "5.29.0", 20 | "@typescript-eslint/parser": "5.29.0", 21 | "builtin-modules": "3.3.0", 22 | "esbuild": "0.14.47", 23 | "jest": "^29.5.0", 24 | "obsidian": "latest", 25 | "ts-jest": "^29.1.0", 26 | "tslib": "2.4.0", 27 | "typescript": "4.7.4" 28 | } 29 | } -------------------------------------------------------------------------------- /src/controllers/viewController.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { Editor } from 'obsidian'; 14 | import { Suggestion } from 'src/model/suggestion'; 15 | import { CrossbowSettingsService } from 'src/services/settingsService'; 16 | import { CrossbowView } from 'src/view/view'; 17 | 18 | export class CrossbowViewController { 19 | public static MANUAL_REFRESH_BUTTON_ID = 'cb-refresh-button'; 20 | 21 | constructor(private readonly settingsService: CrossbowSettingsService) {} 22 | 23 | public async revealOrCreateView(): Promise { 24 | const existing = app.workspace.getLeavesOfType(CrossbowView.viewType); 25 | 26 | if (existing.length) { 27 | app.workspace.revealLeaf(existing[0]); 28 | return; 29 | } 30 | 31 | await app.workspace.getRightLeaf(false).setViewState({ 32 | type: CrossbowView.viewType, 33 | active: true, 34 | }); 35 | 36 | app.workspace.revealLeaf(app.workspace.getLeavesOfType(CrossbowView.viewType)[0]); 37 | } 38 | 39 | public doesCrossbowViewExist(): boolean { 40 | return app.workspace.getLeavesOfType(CrossbowView.viewType).length > 0; 41 | } 42 | 43 | public unloadView(): void { 44 | this.getCrossbowView()?.unload(); 45 | } 46 | 47 | public addOrUpdateSuggestions(suggestions: Suggestion[], targetEditor: Editor, fileHasChanged: boolean): void { 48 | const view = this.getCrossbowView(); 49 | 50 | if (!view) return; 51 | if (fileHasChanged) view.clear(); 52 | 53 | const showManualRefreshButton = !this.settingsService.getSettings().useAutoRefresh; 54 | view.update(suggestions, targetEditor, showManualRefreshButton); 55 | } 56 | 57 | private getCrossbowView(): CrossbowView | undefined { 58 | return app.workspace.getLeavesOfType(CrossbowView.viewType)[0]?.view as CrossbowView; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/icons.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { addIcon } from 'obsidian'; 14 | 15 | const crossbowIcon = { 16 | name: 'crossbow', 17 | svg: ` 18 | 19 | 20 | 21 | `, 22 | }; 23 | 24 | export const registerCrossbowIcons = () => { 25 | addIcon(crossbowIcon.name, crossbowIcon.svg); 26 | }; 27 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { App, CachedMetadata, MarkdownView, Plugin, PluginManifest, TAbstractFile, TFile } from 'obsidian'; 14 | import { CrossbowViewController } from './controllers/viewController'; 15 | import { registerCrossbowIcons } from './icons'; 16 | import { CrossbowIndexingService } from './services/indexingService'; 17 | import { CrossbowLoggingService } from './services/loggingService'; 18 | import { CrossbowPluginSettings, CrossbowSettingsService, DEFAULT_SETTINGS } from './services/settingsService'; 19 | import { CrossbowSuggestionsService } from './services/suggestionsService'; 20 | import { CrossbowTokenizationService } from './services/tokenizationService'; 21 | import { CrossbowUtilsService } from './services/utilsService'; 22 | import { CrossbowSettingTab } from './settings'; 23 | import { registerTreeElements } from './view/tree/tree'; 24 | import { CrossbowView } from './view/view'; 25 | 26 | export default class CrossbowPlugin extends Plugin { 27 | private readonly settingsService: CrossbowSettingsService; 28 | private readonly loggingService: CrossbowLoggingService; 29 | private readonly indexingService: CrossbowIndexingService; 30 | private readonly tokenizationService: CrossbowTokenizationService; 31 | private readonly suggestionsService: CrossbowSuggestionsService; 32 | private readonly utilsService: CrossbowUtilsService; 33 | 34 | private readonly viewController: CrossbowViewController; 35 | 36 | private currentFile: TFile; 37 | private metadataChangedTimeout: ReturnType; 38 | private fileOpenTimeout: ReturnType; 39 | 40 | public constructor(app: App, manifest: PluginManifest) { 41 | super(app, manifest); 42 | 43 | this.settingsService = new CrossbowSettingsService(this.onSettingsChanged); 44 | this.loggingService = new CrossbowLoggingService(this.settingsService); 45 | this.indexingService = new CrossbowIndexingService(this.settingsService, this.loggingService); 46 | this.tokenizationService = new CrossbowTokenizationService(); 47 | this.suggestionsService = new CrossbowSuggestionsService(this.settingsService, this.indexingService); 48 | this.utilsService = new CrossbowUtilsService(); 49 | 50 | this.viewController = new CrossbowViewController(this.settingsService); 51 | } 52 | 53 | /** @implements {@link Plugin.onload} */ 54 | public async onload(): Promise { 55 | // Load settings 56 | const settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()) as CrossbowPluginSettings; 57 | this.settingsService.setSettings(settings); // Set, but don't save so we don't trigger a run 58 | 59 | // Register view elements 60 | registerCrossbowIcons(); 61 | registerTreeElements(); 62 | 63 | this.registerView(CrossbowView.viewType, (leaf) => new CrossbowView(leaf, this.onManualRefreshButtonClick)); 64 | 65 | // Ribbon icon to access the crossbow pane 66 | this.addRibbonIcon('crossbow', 'Crossbow', async (ev: MouseEvent) => { 67 | await this.viewController.revealOrCreateView(); 68 | 69 | // Run initially 70 | this.setActiveFile(); 71 | this.runWithCacheUpdate(true); 72 | }); 73 | 74 | // Settings-tab to configure crossbow 75 | this.addSettingTab(new CrossbowSettingTab(this.app, this, this.settingsService, this.utilsService)); 76 | 77 | // Register event handlers 78 | this.registerEvent(this.app.workspace.on('file-open', this.onFileOpen)); 79 | this.registerEvent(this.app.metadataCache.on('changed', this.onMetadataChange)); 80 | 81 | this.registerEvent(this.app.vault.on('rename', this.onFileRename)); 82 | this.registerEvent(this.app.vault.on('delete', this.onFileDelete)); 83 | 84 | this.loggingService.debugLog('Crossbow is ready.'); 85 | } 86 | 87 | public onunload() { 88 | this.viewController.unloadView(); 89 | this.indexingService.clearCache(); 90 | 91 | this.loggingService.debugLog('Unloaded Crossbow.'); 92 | } 93 | 94 | public runWithCacheUpdate(fileHasChanged: boolean): void { 95 | this.indexingService.indexVault(this.app.vault); 96 | this.runWithoutCacheUpdate(fileHasChanged); 97 | } 98 | 99 | public runWithoutCacheUpdate(fileHasChanged: boolean): void { 100 | // Get editor of current file 101 | const fileView = app.workspace 102 | .getLeavesOfType('markdown') 103 | .find((leaf) => leaf.view instanceof MarkdownView && leaf.view.file === this.currentFile)?.view as 104 | | MarkdownView 105 | | undefined; 106 | 107 | // #26 https://github.com/shoedler/crossbow/issues/26 - Don't know why we cannot set the mode programmatically. 108 | // console.log('fileView mode', fileView?.getMode()); // 'preview' is 'Reading' mode, 'source' is 'Editing' mode (aka. livePreview) 109 | // (fileView as any).setMode('source'); 110 | 111 | if (!fileView) return; 112 | 113 | const targetEditor = fileView.editor; 114 | 115 | if (!targetEditor) return; 116 | 117 | const wordLookup = this.tokenizationService.getWordLookupFromEditor(targetEditor); 118 | const suggestions = this.suggestionsService.getSuggestionsFromWordlookup(wordLookup, this.currentFile); 119 | 120 | this.loggingService.debugLog(`Created ${suggestions.length} suggestions.`); 121 | 122 | this.viewController.addOrUpdateSuggestions(suggestions, targetEditor, fileHasChanged); 123 | } 124 | 125 | private onMetadataChange = (file: TFile, data: string, cache: CachedMetadata): void => { 126 | if (this.metadataChangedTimeout) clearTimeout(this.metadataChangedTimeout); 127 | 128 | if (!this.settingsService.getSettings().useAutoRefresh) return; 129 | if (!this.viewController.doesCrossbowViewExist()) return; 130 | 131 | this.metadataChangedTimeout = setTimeout(() => { 132 | // Only update cache for the current file 133 | this.indexingService.indexFile(file, cache); 134 | this.runWithoutCacheUpdate(false); 135 | this.loggingService.debugLog(`⚡Metadata cache updated. '${file.basename}'`); 136 | }, this.settingsService.getSettings().autoRefreshDelayMs); // This value is arbitrary (Min. 2600ms). 'onMetadataChange' get's triggerd every ~2 to ~2.5 seconds. 137 | }; 138 | 139 | private onFileDelete = (file: TAbstractFile): void => { 140 | this.loggingService.debugLog(`⚡File deleted. '${file.name}'`); 141 | this.indexingService.clearCacheFromFile(file); 142 | }; 143 | 144 | private onFileRename = (file: TAbstractFile, oldPath: string): void => { 145 | this.loggingService.debugLog(`⚡File renamed. '${file.name}'`); 146 | this.indexingService.clearCacheFromFile(oldPath); 147 | 148 | // TODO: Verify if we could just use: this.indexingService.indexFile(file as TFile); 149 | // Could be problematic since file is TAbstractFile 150 | this.app.metadataCache.trigger('changed', file as TFile, ''); // Trigger metadata change to update cache 151 | }; 152 | 153 | private onFileOpen = (): void => { 154 | if (!this.viewController.doesCrossbowViewExist()) return; 155 | 156 | const prevCurrentFile = this.currentFile; 157 | 158 | this.setActiveFile(); 159 | this.loggingService.debugLog(`⚡File opened. '${this.currentFile?.name}'`); 160 | 161 | if (this.fileOpenTimeout) clearTimeout(this.fileOpenTimeout); 162 | 163 | this.fileOpenTimeout = setTimeout(() => { 164 | if (!prevCurrentFile) this.runWithCacheUpdate(true); // Initial run 165 | else if (this.currentFile !== prevCurrentFile) this.runWithoutCacheUpdate(true); // Opened a different file 166 | }, 100); 167 | }; 168 | 169 | private onSettingsChanged = async (settings: CrossbowPluginSettings) => { 170 | this.loggingService.debugLog('⚡Settings saved.'); 171 | await this.saveData(settings); 172 | this.runWithCacheUpdate(true); 173 | }; 174 | 175 | private onManualRefreshButtonClick = (): void => { 176 | this.loggingService.debugLog('Manually triggered update.'); 177 | this.runWithoutCacheUpdate(true); 178 | }; 179 | 180 | private setActiveFile(): void { 181 | const leaf = this.app.workspace.getMostRecentLeaf(); 182 | if (leaf?.view instanceof MarkdownView && leaf.view.file) { 183 | this.currentFile = leaf.view.file; 184 | } else CrossbowLoggingService.forceLog('warn', 'Unable to determine current editor.'); 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /src/model/suggestion.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { EditorPosition, MarkdownView } from 'obsidian'; 14 | import { CacheMatch } from 'src/services/indexingService'; 15 | import { CrossbowLoggingService } from 'src/services/loggingService'; 16 | import { ITreeNodeContext, ITreeNodeData, TreeItemButtonIcon, TreeNode } from 'src/view/tree/treeNode'; 17 | 18 | export class Suggestion implements ITreeNodeData { 19 | public readonly parent: null = null; 20 | public readonly children: Occurrence[] = []; 21 | public readonly word: string; 22 | 23 | public get suffix(): string { 24 | return this.children.length.toString(); 25 | } 26 | 27 | public get flair(): string { 28 | const ranks = new Set(); 29 | this.children[0].children.forEach((match) => ranks.add(match.cacheMatch.rank)); 30 | 31 | return Array.from(ranks) 32 | .sort((a, b) => (a.codePointAt(0) ?? 0) - (b.codePointAt(0) ?? 0)) 33 | .join(''); 34 | } 35 | 36 | public get subtitle(): null { 37 | return null; 38 | } 39 | 40 | public get actions(): { 41 | name: string; 42 | icon: TreeItemButtonIcon; 43 | callback(this: Suggestion, ev: MouseEvent, ctx: ITreeNodeContext): void; 44 | }[] { 45 | return []; 46 | } 47 | 48 | public get uid(): string { 49 | return this.word; 50 | } 51 | 52 | public get text(): string { 53 | return this.word; 54 | } 55 | 56 | public constructor(word: string, matches: CacheMatch[], matchOccurrences: EditorPosition[]) { 57 | this.word = word; 58 | this.children = matchOccurrences.map((p) => { 59 | const matchOccurrenceEnd = { ch: p.ch + word.length, line: p.line } as EditorPosition; 60 | return new Occurrence(this, p, matchOccurrenceEnd, matches); 61 | }); 62 | } 63 | 64 | public sortChildren(): void { 65 | this.children.sort((a, b) => a.editorPosition.line - b.editorPosition.line).forEach((occ) => occ.sortChildren()); 66 | } 67 | } 68 | 69 | export class Occurrence implements ITreeNodeData { 70 | public readonly parent: Suggestion; 71 | public readonly children: Match[] = []; 72 | public readonly editorPosition: EditorPosition; 73 | public readonly editorEndPosition: EditorPosition; 74 | 75 | public get suffix(): null { 76 | return null; 77 | } 78 | 79 | public get flair(): null { 80 | return null; 81 | } 82 | 83 | public get subtitle(): null { 84 | return null; 85 | } 86 | 87 | public get actions(): { 88 | name: string; 89 | icon: TreeItemButtonIcon; 90 | callback(this: Occurrence, ev: MouseEvent, ctx: ITreeNodeContext): void; 91 | }[] { 92 | return [ 93 | { 94 | name: 'Scroll into View', 95 | icon: TreeItemButtonIcon.Scroll, 96 | callback(ev, ctx) { 97 | this.scrollIntoView(ctx); 98 | ev.stopPropagation(); 99 | ev.preventDefault(); 100 | }, 101 | }, 102 | ]; 103 | } 104 | 105 | public get uid(): string { 106 | return `${this.editorPosition.line}:${this.editorPosition.ch}`; 107 | } 108 | 109 | public get text(): string { 110 | return `On line ${this.editorPosition.line + 1}:${this.editorPosition.ch + 1}`; 111 | } 112 | 113 | public constructor( 114 | parent: Suggestion, 115 | editorPosition: EditorPosition, 116 | editorEndPosition: EditorPosition, 117 | cacheMatches: CacheMatch[] 118 | ) { 119 | this.parent = parent; 120 | this.editorPosition = editorPosition; 121 | this.editorEndPosition = editorEndPosition; 122 | this.children = cacheMatches.map((m) => new Match(this, m)); 123 | } 124 | 125 | public sortChildren(): void { 126 | this.children.sort((a, b) => (a.cacheMatch.rank.codePointAt(0) ?? 0) - (b.cacheMatch.rank.codePointAt(0) ?? 0)); 127 | } 128 | 129 | public onClick(this: Occurrence, ctx: ITreeNodeContext): void { 130 | if (ctx.self.isCollapsed()) { 131 | this.scrollIntoView(ctx); 132 | } 133 | } 134 | 135 | public scrollIntoView(ctx: ITreeNodeContext): void { 136 | ctx.targetEditor.setSelection(this.editorPosition, this.editorEndPosition); 137 | ctx.targetEditor.scrollIntoView({ from: this.editorPosition, to: this.editorEndPosition }, true); 138 | } 139 | } 140 | 141 | export class Match implements ITreeNodeData { 142 | public readonly parent: Occurrence; 143 | public readonly cacheMatch: CacheMatch; 144 | 145 | public constructor(parent: Occurrence, cacheMatch: CacheMatch) { 146 | this.parent = parent; 147 | this.cacheMatch = cacheMatch; 148 | } 149 | 150 | public get suffix(): string | null { 151 | return this.cacheMatch.type; 152 | } 153 | 154 | public get flair(): string | null { 155 | return null; 156 | } 157 | 158 | public get subtitle(): string | null { 159 | return this.cacheMatch.type === 'File' ? null : this.cacheMatch.file.name; 160 | } 161 | 162 | public get actions(): { 163 | name: string; 164 | icon: TreeItemButtonIcon; 165 | callback(this: Match, ev: MouseEvent, ctx: ITreeNodeContext): void; 166 | }[] { 167 | return [ 168 | { 169 | name: 'Use', 170 | icon: TreeItemButtonIcon.Inspect, 171 | callback(ev, ctx) { 172 | (ctx.self.parentElement?.parentElement as TreeNode).setDisable(); 173 | ctx.targetEditor.replaceRange(this.createLink(), this.parent.editorPosition, this.parent.editorEndPosition); 174 | }, 175 | }, 176 | { 177 | name: 'Go To Source', 178 | icon: TreeItemButtonIcon.Search, 179 | callback(ev, ctx) { 180 | const leaf = app.workspace.getLeaf(true); 181 | 182 | leaf.openFile(this.cacheMatch.file, { active: false }).then(() => { 183 | if (leaf.view instanceof MarkdownView) { 184 | app.workspace.setActiveLeaf(leaf); 185 | 186 | if (this.cacheMatch.item?.position) { 187 | const from = { 188 | ch: this.cacheMatch.item.position.start.col, 189 | line: this.cacheMatch.item.position.start.line + 1, 190 | }; 191 | const to = { 192 | ch: this.cacheMatch.item.position.end.col, 193 | line: this.cacheMatch.item.position.end.line + 1, 194 | }; 195 | 196 | leaf.view.editor.scrollIntoView({ from, to }, true); 197 | } 198 | } else { 199 | CrossbowLoggingService.forceLog('warn', 'Could not go to source, not a markdown file'); 200 | leaf.detach(); 201 | } 202 | }); 203 | }, 204 | }, 205 | ]; 206 | } 207 | 208 | public get uid(): string { 209 | return `${this.cacheMatch.text}|${this.cacheMatch.file.path}`; 210 | } 211 | 212 | public get text(): string { 213 | return `${this.cacheMatch.rank} ${this.cacheMatch.text}`; 214 | } 215 | 216 | public sortChildren(): void {} 217 | 218 | public createLink(): string { 219 | const word = this.parent.parent.word; 220 | 221 | return this.cacheMatch.item 222 | ? app.fileManager.generateMarkdownLink( 223 | this.cacheMatch.file, 224 | this.cacheMatch.text, 225 | '#' + this.cacheMatch.text, 226 | word 227 | ) 228 | : app.fileManager.generateMarkdownLink(this.cacheMatch.file, this.cacheMatch.text, undefined, word); 229 | } 230 | } 231 | -------------------------------------------------------------------------------- /src/services/indexingService.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { CachedMetadata, FileStats, HeadingCache, TFile, TFolder, TagCache, Vault } from 'obsidian'; 14 | import { CrossbowIndexingService, SourceCacheEntryLookupMap } from './indexingService'; 15 | import { CrossbowLoggingService } from './loggingService'; 16 | import { CrossbowPluginSettings, CrossbowSettingsService, DEFAULT_SETTINGS } from './settingsService'; 17 | 18 | const proto = CrossbowIndexingService.prototype; 19 | 20 | describe(CrossbowIndexingService.constructor.name, () => { 21 | describe(`${proto.indexFile.name}()`, () => { 22 | it('should generate cache entries for headings, tags and one for the file itself', () => { 23 | const fileName = 'testFile'; 24 | const file = createFileMock(fileName); 25 | const metadata = createMetadataCacheMock(); 26 | const service = createServiceMock(); 27 | 28 | service.indexFile(file, metadata); 29 | const fileCache = service.getCache()[file.path]; 30 | 31 | // Key count 32 | expect(Object.keys(fileCache)).toHaveLength(5); 33 | expect(Object.values(fileCache).filter((value) => value.type === 'File')).toHaveLength(1); 34 | expect(Object.values(fileCache).filter((value) => value.type === 'Heading')).toHaveLength(3); 35 | expect(Object.values(fileCache).filter((value) => value.type === 'Tag')).toHaveLength(1); 36 | 37 | // Should contain file cache entry 38 | expect(fileCache[fileName]).toBeDefined(); 39 | expect(fileCache[fileName].type).toBe('File'); 40 | 41 | if (metadata.headings === undefined) { 42 | throw new Error('Metadata headings are undefined'); 43 | } 44 | 45 | // Should contain heading cache entries 46 | metadata.headings.forEach((headingCache) => { 47 | expect(fileCache[headingCache.heading]).toBeDefined(); 48 | expect(fileCache[headingCache.heading].type).toBe('Heading'); 49 | expect(fileCache[headingCache.heading].file).toBe(file); 50 | expect(fileCache[headingCache.heading].text).toBe(headingCache.heading); 51 | }); 52 | 53 | if (metadata.tags === undefined) { 54 | throw new Error('Metadata tags are undefined'); 55 | } 56 | 57 | // Should contain tag cache entries 58 | metadata.tags.forEach((tagCache) => { 59 | expect(fileCache[tagCache.tag]).toBeDefined(); 60 | expect(fileCache[tagCache.tag].type).toBe('Tag'); 61 | expect(fileCache[tagCache.tag].file).toBe(file); 62 | expect(fileCache[tagCache.tag].text).toBe(tagCache.tag); 63 | }); 64 | }); 65 | 66 | it('should not duplicate cache entries when file cache is provided', () => { 67 | const file = createFileMock('testFile'); 68 | const metadata = createMetadataCacheMock(); 69 | const service = createServiceMock(); 70 | 71 | service.indexFile(file, metadata); 72 | expect(Object.keys(service.getCache()[file.path])).toHaveLength(5); 73 | 74 | service.indexFile(file, metadata); 75 | expect(Object.keys(service.getCache()[file.path])).toHaveLength(5); 76 | }); 77 | 78 | it('should not index files which are on the folder ignore list', () => { 79 | const file = createFileMock('testFile'); 80 | file.path = 'testFolder/testFile'; 81 | const metadata = createMetadataCacheMock(); 82 | const service = createServiceMock({ ignoreVaultFolders: ['testFolder'] }); 83 | 84 | service.indexFile(file, metadata); 85 | expect(service.getCache()).toEqual({}); 86 | }); 87 | }); 88 | 89 | describe(`${proto.clearCacheFromFile.name}()`, () => { 90 | it('should clear cache entries (headings, tags and the file)', () => { 91 | const file: TFile = createFileMock('testFile'); 92 | const metadata = createMetadataCacheMock(); 93 | const service = createServiceMock(); 94 | 95 | service.indexFile(file, metadata); 96 | expect(Object.keys(service.getCache()[file.path])).toHaveLength(5); 97 | 98 | service.clearCacheFromFile(file); 99 | 100 | expect(service.getCache()[file.path]).toBeUndefined(); 101 | expect(Object.keys(Object.keys(service.getCache()).filter((filePath) => filePath === file.path))).toHaveLength(0); 102 | }); 103 | 104 | it("shouldn't clear cache entries (headings, tags and the file) of other files", () => { 105 | const fileName1 = 'testFile'; 106 | const file1 = createFileMock(fileName1); 107 | const metadata1 = createMetadataCacheMock(); 108 | 109 | const fileName2 = 'testFile2'; 110 | const file2 = createFileMock(fileName2); 111 | const metadata2 = createMetadataCacheMock(); 112 | 113 | const service = createServiceMock(); 114 | 115 | service.indexFile(file1, metadata1); 116 | service.indexFile(file2, metadata2); 117 | 118 | expect(countCacheEntries(service.getCache())).toEqual(10); 119 | expect(getCacheSources(service.getCache())).toEqual([file1.path, file2.path]); 120 | 121 | service.clearCacheFromFile(file1); 122 | 123 | expect(countCacheEntries(service.getCache())).toEqual(5); 124 | expect(getCacheSources(service.getCache())).toEqual([file2.path]); 125 | }); 126 | }); 127 | 128 | describe(`${proto.clearCache.name}()`, () => { 129 | it('should clear cache', () => { 130 | const fileName1 = 'testFile'; 131 | const file1 = createFileMock(fileName1); 132 | const metadata1 = createMetadataCacheMock(); 133 | 134 | const fileName2 = 'testFile2'; 135 | const file2 = createFileMock(fileName2); 136 | const metadata2 = createMetadataCacheMock(); 137 | 138 | const service = createServiceMock(); 139 | 140 | service.indexFile(file1, metadata1); 141 | service.indexFile(file2, metadata2); 142 | 143 | expect(countCacheEntries(service.getCache())).toEqual(10); 144 | expect(getCacheSources(service.getCache())).toEqual([file1.path, file2.path]); 145 | 146 | service.clearCache(); 147 | 148 | expect(countCacheEntries(service.getCache())).toEqual(0); 149 | expect(getCacheSources(service.getCache())).toEqual([]); 150 | }); 151 | }); 152 | }); 153 | 154 | const settingsServiceMock = new CrossbowSettingsService((settings) => Promise.resolve()); 155 | const loggingService = new CrossbowLoggingService(settingsServiceMock); 156 | 157 | settingsServiceMock.saveSettings(DEFAULT_SETTINGS); 158 | 159 | const createServiceMock = (overrideSettings?: Partial): CrossbowIndexingService => { 160 | if (overrideSettings) { 161 | const settings = settingsServiceMock.getSettings(); 162 | Object.entries(overrideSettings).forEach(([key, value]) => { 163 | // @ts-ignore 164 | settings[key] = value; 165 | }); 166 | settingsServiceMock.saveSettings(settings); 167 | } 168 | return new CrossbowIndexingService(settingsServiceMock, loggingService); 169 | }; 170 | 171 | const createFileMock = (fileName: string): TFile => ({ 172 | basename: fileName, 173 | name: `${fileName}Name`, 174 | path: `./${fileName}`, 175 | extension: 'md', 176 | stat: null as unknown as FileStats, 177 | vault: null as unknown as Vault, 178 | parent: null as unknown as TFolder, 179 | }); 180 | 181 | const createMetadataCacheMock = (headingsCount = 3, tagsCount = 1): CachedMetadata => { 182 | const headings: HeadingCache[] = []; 183 | for (let index = 0; index < headingsCount; index++) { 184 | headings.push({ 185 | level: index + 1, 186 | heading: `Heading ${index + 1}`, 187 | position: { 188 | start: { line: index, col: 0, offset: 0 }, 189 | end: { line: index, col: 8 + index.toString().length, offset: 0 }, 190 | }, 191 | }); 192 | } 193 | 194 | const tags: TagCache[] = []; 195 | for (let index = 0; index < tagsCount; index++) { 196 | tags.push({ 197 | tag: `Tag ${index + 1}`, 198 | position: { 199 | start: { line: index + headingsCount, col: 0, offset: 0 }, 200 | end: { line: index + headingsCount, col: 5 + index.toString().length, offset: 0 }, 201 | }, 202 | }); 203 | } 204 | 205 | return { headings, tags }; 206 | }; 207 | 208 | const getCacheSources = (cache: SourceCacheEntryLookupMap): string[] => Object.keys(cache); 209 | const countCacheEntries = (cache: SourceCacheEntryLookupMap): number => 210 | Object.values(cache).reduce((a, b) => a + Object.values(b).length, 0); 211 | -------------------------------------------------------------------------------- /src/services/indexingService.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { CacheItem, CachedMetadata, TAbstractFile, TFile, Vault } from 'obsidian'; 14 | import { CrossbowLoggingService } from './loggingService'; 15 | import { CrossbowSettingsService } from './settingsService'; 16 | 17 | type CacheEntryLookup = { [key: string]: CacheEntry }; 18 | 19 | export type SourceCacheEntryLookupMap = { [key: TFile['path']]: CacheEntryLookup }; 20 | 21 | export interface CacheEntry { 22 | file: TFile; 23 | item?: CacheItem; 24 | text: string; 25 | type: 'Tag' | 'File' | 'Heading'; 26 | } 27 | 28 | export interface CacheMatch extends CacheEntry { 29 | rank: '🏆' | '🥇' | '🥈' | '🥉'; 30 | } 31 | 32 | export class CrossbowIndexingService { 33 | private crossbowCache: SourceCacheEntryLookupMap = {}; 34 | 35 | public constructor( 36 | private readonly settingsService: CrossbowSettingsService, 37 | private readonly loggingService: CrossbowLoggingService 38 | ) {} 39 | 40 | public getCache(): SourceCacheEntryLookupMap { 41 | return this.crossbowCache; 42 | } 43 | 44 | public indexVault(vault: Vault): void { 45 | this.clearCache(); 46 | 47 | const files = vault.getFiles(); 48 | files.forEach((file) => this.indexFile(file)); 49 | } 50 | 51 | public clearCacheFromFile(path: string): void; 52 | public clearCacheFromFile(file: TAbstractFile): void; 53 | public clearCacheFromFile(fileOrPath: TAbstractFile | string): void { 54 | const path = typeof fileOrPath === 'string' ? fileOrPath : fileOrPath.path; 55 | this.loggingService.debugLog(`Clearing cache for file ${path}`); 56 | delete this.crossbowCache[path]; 57 | } 58 | 59 | // 'cache' can be passed in, if this is called from an event handler which already has the cache 60 | // This will prevent the cache from being retrieved twice 61 | public indexFile(file: TFile, cache?: CachedMetadata): void { 62 | const settings = this.settingsService.getSettings(); 63 | 64 | if (file.extension !== 'md') return; 65 | if (settings.ignoreVaultFolders.some((folderOrPath) => file.path.startsWith(folderOrPath))) return; 66 | if (cache) this.clearCacheFromFile(file); 67 | 68 | const metadata = cache ? cache : app.metadataCache.getFileCache(file); 69 | 70 | if (file.basename.length >= settings.minimumSuggestionWordLength) 71 | this.addOrUpdateCacheEntry({ file, text: file.basename, type: 'File' }, file); 72 | 73 | if (metadata) { 74 | if (metadata.headings) 75 | metadata.headings.forEach((headingCache) => 76 | this.addOrUpdateCacheEntry( 77 | { 78 | item: headingCache, 79 | file, 80 | text: headingCache.heading, 81 | type: 'Heading', 82 | }, 83 | file 84 | ) 85 | ); 86 | if (metadata.tags) 87 | metadata.tags.forEach((tagCache) => 88 | this.addOrUpdateCacheEntry( 89 | { 90 | item: tagCache, 91 | file, 92 | text: tagCache.tag, 93 | type: 'Tag', 94 | }, 95 | file 96 | ) 97 | ); 98 | } 99 | } 100 | 101 | public clearCache(): void { 102 | this.crossbowCache = {}; 103 | } 104 | 105 | private addOrUpdateCacheEntry(entry: CacheEntry, source: TFile): void { 106 | this.crossbowCache[source.path] = this.crossbowCache[source.path] ? this.crossbowCache[source.path] : {}; 107 | this.crossbowCache[source.path][entry.text] = entry; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/services/loggingService.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { CrossbowSettingsService } from './settingsService'; 14 | 15 | export class CrossbowLoggingService { 16 | private static LOGGER_PREFIX = '🏹: '; 17 | 18 | public constructor(private readonly settingsService: CrossbowSettingsService) {} 19 | 20 | public debugLog(message: string): void { 21 | this.settingsService.getSettings().useLogging && console.log(CrossbowLoggingService.LOGGER_PREFIX + message); 22 | } 23 | 24 | public debugWarn(message: string): void { 25 | this.settingsService.getSettings().useLogging && console.warn(CrossbowLoggingService.LOGGER_PREFIX + message); 26 | } 27 | 28 | public static forceLog(type: 'warn' | 'log', message: string): void { 29 | console[type](CrossbowLoggingService.LOGGER_PREFIX + message); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/services/settingsService.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | export interface CrossbowPluginSettings { 14 | ignoredWordsCaseSensisitve: string[]; 15 | suggestInSameFile: boolean; 16 | ignoreSuggestionsWhichStartWithLowercaseLetter: boolean; 17 | ignoreOccurrencesWhichStartWithLowercaseLetter: boolean; 18 | minimumSuggestionWordLength: number; 19 | useLogging: boolean; 20 | useAutoRefresh: boolean; 21 | autoRefreshDelayMs: number; 22 | ignoreVaultFolders: string[]; 23 | } 24 | 25 | export const DEFAULT_SETTINGS: CrossbowPluginSettings = { 26 | ignoredWordsCaseSensisitve: ['image', 'the', 'always', 'some'], 27 | suggestInSameFile: false, 28 | ignoreSuggestionsWhichStartWithLowercaseLetter: true, 29 | ignoreOccurrencesWhichStartWithLowercaseLetter: false, 30 | minimumSuggestionWordLength: 3, 31 | useLogging: false, 32 | useAutoRefresh: true, 33 | autoRefreshDelayMs: 2600, 34 | ignoreVaultFolders: [], 35 | }; 36 | 37 | export class CrossbowSettingsService { 38 | private settings: CrossbowPluginSettings; 39 | 40 | constructor(private onSettingsChange: (settings: CrossbowPluginSettings) => Promise) { 41 | this.settings = DEFAULT_SETTINGS; 42 | } 43 | 44 | public getSettings(): CrossbowPluginSettings { 45 | return this.settings; 46 | } 47 | 48 | public setSettings(settings: CrossbowPluginSettings): void { 49 | this.settings = settings; 50 | } 51 | 52 | public async saveSettings(settings?: CrossbowPluginSettings): Promise { 53 | this.settings = settings ?? this.settings; 54 | await this.onSettingsChange(this.settings); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/services/suggestionsService.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { TFile } from 'obsidian'; 14 | import { Suggestion } from 'src/model/suggestion'; 15 | import { CacheMatch, CrossbowIndexingService } from './indexingService'; 16 | import { CrossbowSettingsService } from './settingsService'; 17 | import { WordLookup } from './tokenizationService'; 18 | 19 | export class CrossbowSuggestionsService { 20 | public constructor( 21 | private readonly settingsService: CrossbowSettingsService, 22 | private readonly indexingService: CrossbowIndexingService 23 | ) {} 24 | 25 | public getSuggestionsFromWordlookup(wordLookup: WordLookup, currentFile: TFile): Suggestion[] { 26 | if (!wordLookup) return []; 27 | 28 | const result: Suggestion[] = []; 29 | const cache = this.indexingService.getCache(); 30 | const settings = this.settingsService.getSettings(); 31 | 32 | const wordEntries = Object.entries(wordLookup); 33 | 34 | for (let i = 0; i < wordEntries.length; i++) { 35 | const [word, editorPositions] = wordEntries[i]; 36 | const lowercaseWord = word.toLowerCase(); 37 | 38 | const matches: CacheMatch[] = []; 39 | 40 | // Find matches in the cache 41 | const cacheValues = Object.values(cache); 42 | 43 | for (let j = 0; j < cacheValues.length; j++) { 44 | const cacheLookup = cacheValues[j]; 45 | const cacheEntries = Object.entries(cacheLookup); 46 | 47 | for (let k = 0; k < cacheEntries.length; k++) { 48 | const [cacheKey, cacheValue] = cacheEntries[k]; 49 | const lowercaseCacheKey = cacheKey.toLowerCase(); 50 | 51 | if (matches.length >= 300) continue; 52 | 53 | // If reference is in the same file, and we don't want to suggest references in the same file, skip 54 | if (!settings.suggestInSameFile && cacheValue.file === currentFile) continue; 55 | 56 | // If we have a case-sensitive exact match, we always add it, even if it does not satisfy the other filters. Say we have a chapter with a heading 'C' (eg. the programming language) 57 | // We want to match a word 'C' in the current editor, even if it is too short or is on the ignore list. 58 | if (cacheKey === word) { 59 | matches.push({ ...cacheValue, rank: '🏆' }); 60 | continue; 61 | } 62 | 63 | // If the word is too short, skip 64 | if (word.length <= 3) continue; 65 | 66 | // If the cache key is too short, skip 67 | if (cacheKey.length <= settings.minimumSuggestionWordLength) continue; 68 | 69 | // If the word is not a substring of the key or the key is not a substring of the word, skip 70 | if ((lowercaseCacheKey.includes(lowercaseWord) || lowercaseWord.includes(lowercaseCacheKey)) === false) 71 | continue; 72 | 73 | // If the word does not start with an uppercase letter, skip 74 | if (settings.ignoreOccurrencesWhichStartWithLowercaseLetter && cacheKey[0] === lowercaseCacheKey[0]) continue; 75 | 76 | // If the cache key does not start with an uppercase letter, skip 77 | if (settings.ignoreSuggestionsWhichStartWithLowercaseLetter && word[0] === lowercaseWord[0]) continue; 78 | 79 | // If the word is a case-insensitive exact match, add as a very good suggestion 80 | if (lowercaseCacheKey === lowercaseWord) { 81 | matches.push({ ...cacheValue, rank: '🥇' }); 82 | continue; 83 | } 84 | 85 | // If the lengths differ too much, add as not-very-good suggestion 86 | if ((1 / cacheKey.length) * word.length <= 0.2) { 87 | matches.push({ ...cacheValue, rank: '🥉' }); 88 | continue; 89 | } 90 | 91 | // Else, add as a mediocre suggestion 92 | matches.push({ ...cacheValue, rank: '🥈' }); 93 | } 94 | } 95 | 96 | if (matches.length > 0) { 97 | result.push(new Suggestion(word, matches, editorPositions)); 98 | } 99 | } 100 | 101 | // Sort the result 102 | result.sort((a, b) => a.uid.localeCompare(b.uid)).forEach((suggestion) => suggestion.sortChildren()); 103 | 104 | // Remove ignored words from the result 105 | return this.removeIgnoredWords(result); 106 | } 107 | 108 | private removeIgnoredWords(suggestions: Suggestion[]): Suggestion[] { 109 | const ignoredWordsCaseSensisitve = this.settingsService.getSettings().ignoredWordsCaseSensisitve; 110 | const ignoredWordsCache: { [key: string]: boolean } = {}; 111 | 112 | const result = suggestions.filter((suggestion) => { 113 | if (ignoredWordsCache[suggestion.word] === undefined) { 114 | ignoredWordsCache[suggestion.word] = !ignoredWordsCaseSensisitve.includes(suggestion.word); 115 | } 116 | 117 | return ignoredWordsCache[suggestion.word]; 118 | }); 119 | 120 | return result; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/services/tokenizationService.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | /* eslint-disable no-useless-escape */ // Reson: `testFile` 14 | 15 | import { writeFileSync } from 'fs'; 16 | import { Editor } from 'obsidian'; 17 | import { CrossbowTokenizationService, WordLookup } from './tokenizationService'; 18 | 19 | const proto = CrossbowTokenizationService.prototype; 20 | 21 | describe(CrossbowTokenizationService.constructor.name, () => { 22 | describe(`${CrossbowTokenizationService.redactText.name}()`, () => { 23 | it('should redact code blocks (```) from a string, leaving spaces in its place', () => { 24 | const input___ = 'This is a ```\ncode block\n``` string'; 25 | const expected = 'This is a \n \n string'; 26 | const actual = CrossbowTokenizationService.redactText(input___); 27 | expect(actual).toEqual(expected); 28 | }); 29 | 30 | it('should redact metadata (---) from a string, leaving spaces in its place', () => { 31 | const input___ = '---\nThis is metadata\n---\r\n This is not'; 32 | const expected = ' \n \n \r\n This is not'; 33 | const actual = CrossbowTokenizationService.redactText(input___); 34 | expect(actual).toEqual(expected); 35 | }); 36 | 37 | it('should redact hashtags (#) from a string, leaving spaces in its place', () => { 38 | const input___ = 'This is a #hashtag string - can even have multiple ###############hashtags'; 39 | const expected = 'This is a string - can even have multiple '; 40 | const actual = CrossbowTokenizationService.redactText(input___); 41 | expect(actual).toEqual(expected); 42 | }); 43 | 44 | it('should redact html comments () from a string, leaving spaces in its place', () => { 45 | const input___ = 'This is a string'; 46 | const expected = 'This is a string'; 47 | const actual = CrossbowTokenizationService.redactText(input___); 48 | expect(actual).toEqual(expected); 49 | }); 50 | 51 | it('should redact html tags () from a string, leaving spaces in its place', () => { 52 | const input___ = 53 | 'A tag . With attributes.
  • nested tags
'; 54 | const expected = 55 | 'A tag . With attributes . nested tags '; 56 | const actual = CrossbowTokenizationService.redactText(input___); 57 | expect(actual).toEqual(expected); 58 | }); 59 | 60 | it('should redact inline latex ($) from a string, leaving spaces in its place', () => { 61 | const input___ = 'This is a $latex$ string'; 62 | const expected = 'This is a string'; 63 | const actual = CrossbowTokenizationService.redactText(input___); 64 | expect(actual).toEqual(expected); 65 | }); 66 | 67 | it('should redact block latex ($$) from a string, leaving spaces in its place', () => { 68 | const input___ = 'This is a $$\nlatex\r\n block\n$$ string, with inline $latex$'; 69 | const expected = 'This is a \n \r\n \n string, with inline '; 70 | const actual = CrossbowTokenizationService.redactText(input___); 71 | expect(actual).toEqual(expected); 72 | }); 73 | 74 | it('should redact obsidian links ([[ & ]]) from a string, leaving spaces in its place', () => { 75 | const input___ = 'This is a [[obsidian link]] string'; 76 | const expected = 'This is a string'; 77 | const actual = CrossbowTokenizationService.redactText(input___); 78 | expect(actual).toEqual(expected); 79 | }); 80 | 81 | it('should redact markdown links ([]()) from a string, leaving spaces in its place', () => { 82 | const input___ = 'This is a [markdown link](https://example.com) string'; 83 | const expected = 'This is a string'; 84 | const actual = CrossbowTokenizationService.redactText(input___); 85 | expect(actual).toEqual(expected); 86 | }); 87 | 88 | it('should redact markdown images (![]()) from a string, leaving spaces in its place', () => { 89 | const input___ = 'This is a ![markdown image](https://example.com) string'; 90 | const expected = 'This is a string'; 91 | const actual = CrossbowTokenizationService.redactText(input___); 92 | expect(actual).toEqual(expected); 93 | }); 94 | }); 95 | 96 | describe(`${CrossbowTokenizationService.cleanWord.name}()`, () => { 97 | it('should remove anything but alphanumeric chars from a word', () => { 98 | const input = 'Word$¨\'^!"*ç"*ç%&/()=?`*'; 99 | const expected = 'Word'; 100 | const actual = CrossbowTokenizationService.cleanWord(input); 101 | expect(actual).toEqual(expected); 102 | }); 103 | }); 104 | 105 | describe(`${proto.getWordLookupFromEditor.name}()`, () => { 106 | const mockEditor = (value: string) => { 107 | return { 108 | value, 109 | getValue: () => value, 110 | offsetToPos: (offset: number) => { 111 | return { 112 | line: 0, 113 | ch: offset, 114 | }; 115 | }, 116 | } as Editor & { value: string }; 117 | }; 118 | 119 | it('should return a word lookup from a string', () => { 120 | const editor = mockEditor('This is a string" with multiple words'); 121 | const service = new CrossbowTokenizationService(); 122 | const expected = { 123 | This: [{ line: 0, ch: 0 }], 124 | is: [{ line: 0, ch: 5 }], 125 | a: [{ line: 0, ch: 8 }], 126 | string: [{ line: 0, ch: 10 }], 127 | with: [{ line: 0, ch: 18 }], 128 | multiple: [{ line: 0, ch: 23 }], 129 | words: [{ line: 0, ch: 32 }], 130 | } as WordLookup; 131 | const actual = service.getWordLookupFromEditor(editor); 132 | expect(actual).toEqual(expected); 133 | }); 134 | 135 | it('should return a word lookup from a testfile', () => { 136 | const editor = mockEditor(testFile); 137 | const service = new CrossbowTokenizationService(); 138 | const actual = service.getWordLookupFromEditor(editor); 139 | 140 | // Dump actual and expected to files for debugging 141 | writeFileSync('src/services/tokenizationService.test.actual.dump.json', JSON.stringify(actual, null, 0)); 142 | writeFileSync( 143 | 'src/services/tokenizationService.test.expected.dump.json', 144 | JSON.stringify(expectedFromTestFile, null, 0) 145 | ); 146 | 147 | expect(actual).toEqual(expectedFromTestFile); 148 | }); 149 | }); 150 | }); 151 | 152 | const expectedFromTestFile = { 153 | '0': [{ line: 0, ch: 2269 }], 154 | '1': [ 155 | { line: 0, ch: 1828 }, 156 | { line: 0, ch: 3328 }, 157 | { line: 0, ch: 4554 }, 158 | ], 159 | '2': [{ line: 0, ch: 3779 }], 160 | '3': [{ line: 0, ch: 1849 }], 161 | '4': [ 162 | { line: 0, ch: 192 }, 163 | { line: 0, ch: 215 }, 164 | { line: 0, ch: 413 }, 165 | { line: 0, ch: 1569 }, 166 | ], 167 | '5': [ 168 | { line: 0, ch: 3135 }, 169 | { line: 0, ch: 3179 }, 170 | { line: 0, ch: 3223 }, 171 | { line: 0, ch: 3289 }, 172 | ], 173 | '9': [{ line: 0, ch: 3331 }], 174 | '51': [{ line: 0, ch: 1916 }], 175 | '93': [{ line: 0, ch: 3786 }], 176 | '185': [{ line: 0, ch: 3754 }], 177 | '1249': [{ line: 0, ch: 3041 }], 178 | '1851': [{ line: 0, ch: 3770 }], 179 | '12494': [{ line: 0, ch: 3066 }], 180 | '12589': [{ line: 0, ch: 3186 }], 181 | '34567': [{ line: 0, ch: 3142 }], 182 | '55555': [{ line: 0, ch: 3098 }], 183 | der: [ 184 | { line: 0, ch: 25 }, 185 | { line: 0, ch: 636 }, 186 | { line: 0, ch: 1200 }, 187 | { line: 0, ch: 1292 }, 188 | { line: 0, ch: 3392 }, 189 | { line: 0, ch: 3527 }, 190 | ], 191 | Statistische: [{ line: 0, ch: 120 }], 192 | Einheit: [ 193 | { line: 0, ch: 133 }, 194 | { line: 0, ch: 267 }, 195 | { line: 0, ch: 574 }, 196 | ], 197 | Beispiel: [ 198 | { line: 0, ch: 141 }, 199 | { line: 0, ch: 403 }, 200 | { line: 0, ch: 496 }, 201 | { line: 0, ch: 621 }, 202 | { line: 0, ch: 1801 }, 203 | { line: 0, ch: 2340 }, 204 | { line: 0, ch: 3023 }, 205 | ], 206 | Schuhe: [ 207 | { line: 0, ch: 151 }, 208 | { line: 0, ch: 420 }, 209 | { line: 0, ch: 461 }, 210 | { line: 0, ch: 640 }, 211 | { line: 0, ch: 667 }, 212 | ], 213 | aussuchen: [{ line: 0, ch: 158 }], 214 | nach: [{ line: 0, ch: 168 }], 215 | Kriterien: [{ line: 0, ch: 173 }], 216 | Man: [ 217 | { line: 0, ch: 184 }, 218 | { line: 0, ch: 2104 }, 219 | ], 220 | hat: [ 221 | { line: 0, ch: 188 }, 222 | { line: 0, ch: 705 }, 223 | ], 224 | Paare: [{ line: 0, ch: 194 }], 225 | zur: [{ line: 0, ch: 200 }], 226 | Auswahl: [{ line: 0, ch: 204 }], 227 | Objekte: [ 228 | { line: 0, ch: 219 }, 229 | { line: 0, ch: 233 }, 230 | ], 231 | Die: [ 232 | { line: 0, ch: 229 }, 233 | { line: 0, ch: 308 }, 234 | { line: 0, ch: 1239 }, 235 | { line: 0, ch: 1579 }, 236 | { line: 0, ch: 3226 }, 237 | ], 238 | werden: [ 239 | { line: 0, ch: 241 }, 240 | { line: 0, ch: 2186 }, 241 | { line: 0, ch: 3299 }, 242 | ], 243 | als: [ 244 | { line: 0, ch: 248 }, 245 | { line: 0, ch: 1316 }, 246 | { line: 0, ch: 1845 }, 247 | ], 248 | statistische: [{ line: 0, ch: 254 }], 249 | bezeichnet: [{ line: 0, ch: 277 }], 250 | Grundgesamtheit: [{ line: 0, ch: 292 }], 251 | Menge: [ 252 | { line: 0, ch: 312 }, 253 | { line: 0, ch: 449 }, 254 | { line: 0, ch: 2578 }, 255 | ], 256 | aller: [ 257 | { line: 0, ch: 318 }, 258 | { line: 0, ch: 455 }, 259 | ], 260 | statistischer: [{ line: 0, ch: 324 }], 261 | Einheiten: [{ line: 0, ch: 338 }], 262 | die: [ 263 | { line: 0, ch: 349 }, 264 | { line: 0, ch: 445 }, 265 | { line: 0, ch: 653 }, 266 | { line: 0, ch: 729 }, 267 | { line: 0, ch: 1079 }, 268 | { line: 0, ch: 1379 }, 269 | { line: 0, ch: 1405 }, 270 | { line: 0, ch: 1599 }, 271 | { line: 0, ch: 1709 }, 272 | { line: 0, ch: 3306 }, 273 | { line: 0, ch: 4641 }, 274 | ], 275 | für: [ 276 | { line: 0, ch: 353 }, 277 | { line: 0, ch: 1375 }, 278 | ], 279 | eine: [ 280 | { line: 0, ch: 357 }, 281 | { line: 0, ch: 1492 }, 282 | { line: 0, ch: 1911 }, 283 | ], 284 | Untersuchung: [{ line: 0, ch: 362 }], 285 | in: [ 286 | { line: 0, ch: 375 }, 287 | { line: 0, ch: 1197 }, 288 | { line: 0, ch: 1289 }, 289 | { line: 0, ch: 1415 }, 290 | { line: 0, ch: 2609 }, 291 | { line: 0, ch: 4040 }, 292 | ], 293 | Frage: [{ line: 0, ch: 378 }], 294 | kommen: [{ line: 0, ch: 384 }], 295 | Im: [ 296 | { line: 0, ch: 393 }, 297 | { line: 0, ch: 486 }, 298 | ], 299 | obigen: [ 300 | { line: 0, ch: 396 }, 301 | { line: 0, ch: 489 }, 302 | { line: 0, ch: 3230 }, 303 | ], 304 | Paar: [ 305 | { line: 0, ch: 415 }, 306 | { line: 0, ch: 662 }, 307 | ], 308 | Könnte: [{ line: 0, ch: 428 }], 309 | aber: [ 310 | { line: 0, ch: 435 }, 311 | { line: 0, ch: 1867 }, 312 | ], 313 | auch: [{ line: 0, ch: 440 }], 314 | sein: [{ line: 0, ch: 468 }], 315 | Merkmale: [{ line: 0, ch: 477 }], 316 | Farbe: [ 317 | { line: 0, ch: 506 }, 318 | { line: 0, ch: 630 }, 319 | { line: 0, ch: 722 }, 320 | ], 321 | Material: [{ line: 0, ch: 513 }], 322 | Absatzhöhe: [{ line: 0, ch: 523 }], 323 | usw: [ 324 | { line: 0, ch: 534 }, 325 | { line: 0, ch: 1851 }, 326 | ], 327 | Eigenschaften: [{ line: 0, ch: 540 }], 328 | einer: [ 329 | { line: 0, ch: 554 }, 330 | { line: 0, ch: 1390 }, 331 | { line: 0, ch: 1923 }, 332 | { line: 0, ch: 1948 }, 333 | { line: 0, ch: 2381 }, 334 | { line: 0, ch: 3414 }, 335 | ], 336 | statistischen: [{ line: 0, ch: 560 }], 337 | Merkmalsausprägung: [{ line: 0, ch: 587 }], 338 | Qualitativ: [ 339 | { line: 0, ch: 610 }, 340 | { line: 0, ch: 2811 }, 341 | { line: 0, ch: 2902 }, 342 | ], 343 | Wenn: [{ line: 0, ch: 648 }], 344 | vier: [{ line: 0, ch: 657 }], 345 | rot: [ 346 | { line: 0, ch: 674 }, 347 | { line: 0, ch: 744 }, 348 | ], 349 | blau: [ 350 | { line: 0, ch: 679 }, 351 | { line: 0, ch: 749 }, 352 | ], 353 | grün: [ 354 | { line: 0, ch: 685 }, 355 | { line: 0, ch: 754 }, 356 | ], 357 | und: [ 358 | { line: 0, ch: 690 }, 359 | { line: 0, ch: 759 }, 360 | { line: 0, ch: 814 }, 361 | { line: 0, ch: 2075 }, 362 | { line: 0, ch: 4571 }, 363 | ], 364 | gelb: [ 365 | { line: 0, ch: 694 }, 366 | { line: 0, ch: 763 }, 367 | ], 368 | sind: [ 369 | { line: 0, ch: 699 }, 370 | { line: 0, ch: 990 }, 371 | { line: 0, ch: 1810 }, 372 | { line: 0, ch: 2088 }, 373 | ], 374 | das: [ 375 | { line: 0, ch: 709 }, 376 | { line: 0, ch: 871 }, 377 | { line: 0, ch: 1185 }, 378 | ], 379 | Merkmal: [ 380 | { line: 0, ch: 713 }, 381 | { line: 0, ch: 846 }, 382 | { line: 0, ch: 862 }, 383 | { line: 0, ch: 1029 }, 384 | { line: 0, ch: 1126 }, 385 | { line: 0, ch: 1189 }, 386 | ], 387 | Ausprägung: [ 388 | { line: 0, ch: 733 }, 389 | { line: 0, ch: 2396 }, 390 | ], 391 | Quantitativ: [ 392 | { line: 0, ch: 774 }, 393 | { line: 0, ch: 2629 }, 394 | { line: 0, ch: 2720 }, 395 | ], 396 | Unterkategorien: [{ line: 0, ch: 788 }], 397 | diskret: [ 398 | { line: 0, ch: 805 }, 399 | { line: 0, ch: 1001 }, 400 | { line: 0, ch: 1134 }, 401 | ], 402 | stetig: [ 403 | { line: 0, ch: 819 }, 404 | { line: 0, ch: 1147 }, 405 | { line: 0, ch: 1266 }, 406 | ], 407 | Ein: [ 408 | { line: 0, ch: 828 }, 409 | { line: 0, ch: 1012 }, 410 | { line: 0, ch: 2250 }, 411 | ], 412 | diskretes: [{ line: 0, ch: 834 }], 413 | ist: [ 414 | { line: 0, ch: 854 }, 415 | { line: 0, ch: 1037 }, 416 | { line: 0, ch: 1154 }, 417 | { line: 0, ch: 1256 }, 418 | { line: 0, ch: 1595 }, 419 | { line: 0, ch: 1777 }, 420 | { line: 0, ch: 1830 }, 421 | { line: 0, ch: 1907 }, 422 | { line: 0, ch: 2272 }, 423 | { line: 0, ch: 4022 }, 424 | { line: 0, ch: 4538 }, 425 | ], 426 | ein: [ 427 | { line: 0, ch: 858 }, 428 | { line: 0, ch: 1096 }, 429 | { line: 0, ch: 1122 }, 430 | { line: 0, ch: 2120 }, 431 | { line: 0, ch: 2143 }, 432 | { line: 0, ch: 2276 }, 433 | { line: 0, ch: 3259 }, 434 | ], 435 | nur: [{ line: 0, ch: 875 }], 436 | endlich: [{ line: 0, ch: 879 }], 437 | viele: [ 438 | { line: 0, ch: 887 }, 439 | { line: 0, ch: 941 }, 440 | ], 441 | Ausprägungen: [ 442 | { line: 0, ch: 893 }, 443 | { line: 0, ch: 947 }, 444 | { line: 0, ch: 1083 }, 445 | ], 446 | oder: [ 447 | { line: 0, ch: 906 }, 448 | { line: 0, ch: 1142 }, 449 | ], 450 | höchstens: [{ line: 0, ch: 911 }], 451 | abzählbar: [{ line: 0, ch: 921 }], 452 | unendlich: [{ line: 0, ch: 931 }], 453 | annehmen: [{ line: 0, ch: 960 }], 454 | kann: [ 455 | { line: 0, ch: 969 }, 456 | { line: 0, ch: 2138 }, 457 | ], 458 | Zählvariablen: [{ line: 0, ch: 976 }], 459 | stets: [{ line: 0, ch: 995 }], 460 | stetiges: [{ line: 0, ch: 1018 }], 461 | hingegen: [{ line: 0, ch: 1041 }], 462 | dadurch: [{ line: 0, ch: 1050 }], 463 | gekennzeichnet: [{ line: 0, ch: 1058 }], 464 | dass: [ 465 | { line: 0, ch: 1074 }, 466 | { line: 0, ch: 4549 }, 467 | ], 468 | Intervall: [ 469 | { line: 0, ch: 1100 }, 470 | { line: 0, ch: 2031 }, 471 | { line: 0, ch: 2744 }, 472 | ], 473 | bilden: [{ line: 0, ch: 1110 }], 474 | Ob: [{ line: 0, ch: 1119 }], 475 | hängt: [{ line: 0, ch: 1159 }], 476 | nicht: [ 477 | { line: 0, ch: 1165 }, 478 | { line: 0, ch: 1962 }, 479 | { line: 0, ch: 3334 }, 480 | ], 481 | davon: [{ line: 0, ch: 1171 }], 482 | ab: [{ line: 0, ch: 1177 }], 483 | wie: [{ line: 0, ch: 1181 }], 484 | Praxis: [ 485 | { line: 0, ch: 1204 }, 486 | { line: 0, ch: 1296 }, 487 | ], 488 | tatsächlich: [{ line: 0, ch: 1211 }], 489 | angegeben: [ 490 | { line: 0, ch: 1223 }, 491 | { line: 0, ch: 1439 }, 492 | ], 493 | wird: [ 494 | { line: 0, ch: 1233 }, 495 | { line: 0, ch: 1449 }, 496 | { line: 0, ch: 4565 }, 497 | ], 498 | Körpergrösse: [{ line: 0, ch: 1243 }], 499 | z: [{ line: 0, ch: 1260 }], 500 | B: [{ line: 0, ch: 1263 }], 501 | obwohl: [{ line: 0, ch: 1274 }], 502 | man: [ 503 | { line: 0, ch: 1281 }, 504 | { line: 0, ch: 4575 }, 505 | ], 506 | sie: [{ line: 0, ch: 1285 }], 507 | kaum: [{ line: 0, ch: 1303 }], 508 | genauer: [{ line: 0, ch: 1308 }], 509 | auf: [{ line: 0, ch: 1320 }], 510 | volle: [{ line: 0, ch: 1324 }], 511 | Zentimeter: [{ line: 0, ch: 1330 }], 512 | gerundet: [{ line: 0, ch: 1341 }], 513 | ausweist: [{ line: 0, ch: 1350 }], 514 | Ähnliches: [{ line: 0, ch: 1360 }], 515 | gilt: [{ line: 0, ch: 1370 }], 516 | Grösse: [{ line: 0, ch: 1383 }], 517 | Wohnung: [{ line: 0, ch: 1396 }], 518 | meist: [{ line: 0, ch: 1409 }], 519 | vollen: [{ line: 0, ch: 1418 }], 520 | Quadratmetern: [{ line: 0, ch: 1425 }], 521 | Skalenniveau: [{ line: 0, ch: 1457 }], 522 | Skalenniveaus: [{ line: 0, ch: 1472 }], 523 | haben: [ 524 | { line: 0, ch: 1486 }, 525 | { line: 0, ch: 3248 }, 526 | ], 527 | hierarchische: [{ line: 0, ch: 1497 }], 528 | Struktur: [ 529 | { line: 0, ch: 1511 }, 530 | { line: 0, ch: 1545 }, 531 | ], 532 | Schwächste: [{ line: 0, ch: 1523 }], 533 | bis: [ 534 | { line: 0, ch: 1535 }, 535 | { line: 0, ch: 1565 }, 536 | ], 537 | Beste: [{ line: 0, ch: 1539 }], 538 | Bild: [ 539 | { line: 0, ch: 1555 }, 540 | { line: 0, ch: 1741 }, 541 | { line: 0, ch: 2319 }, 542 | ], 543 | EG: [{ line: 0, ch: 1561 }], 544 | OG: [{ line: 0, ch: 1572 }], 545 | Wurzelskala: [{ line: 0, ch: 1583 }], 546 | Nominalskala: [ 547 | { line: 0, ch: 1605 }, 548 | { line: 0, ch: 1662 }, 549 | ], 550 | Rangordnung: [ 551 | { line: 0, ch: 1677 }, 552 | { line: 0, ch: 1765 }, 553 | { line: 0, ch: 2063 }, 554 | ], 555 | fehlt: [{ line: 0, ch: 1689 }], 556 | Wie: [{ line: 0, ch: 1696 }], 557 | soll: [{ line: 0, ch: 1700 }], 558 | ich: [{ line: 0, ch: 1705 }], 559 | ordnen: [{ line: 0, ch: 1713 }], 560 | Beispiele: [ 561 | { line: 0, ch: 1724 }, 562 | { line: 0, ch: 1978 }, 563 | { line: 0, ch: 2302 }, 564 | { line: 0, ch: 3810 }, 565 | { line: 0, ch: 4114 }, 566 | ], 567 | Siehe: [ 568 | { line: 0, ch: 1735 }, 569 | { line: 0, ch: 2313 }, 570 | ], 571 | Ordinalskala: [{ line: 0, ch: 1750 }], 572 | vorhanden: [{ line: 0, ch: 1781 }], 573 | Bestes: [{ line: 0, ch: 1794 }], 574 | Schulnoten: [{ line: 0, ch: 1815 }], 575 | schlechter: [{ line: 0, ch: 1834 }], 576 | Es: [ 577 | { line: 0, ch: 1859 }, 578 | { line: 0, ch: 2196 }, 579 | ], 580 | gibt: [ 581 | { line: 0, ch: 1862 }, 582 | { line: 0, ch: 2199 }, 583 | ], 584 | keine: [{ line: 0, ch: 1872 }], 585 | sinnvollen: [{ line: 0, ch: 1879 }], 586 | Abstände: [ 587 | { line: 0, ch: 1891 }, 588 | { line: 0, ch: 2079 }, 589 | ], 590 | zB: [{ line: 0, ch: 1902 }], 591 | an: [ 592 | { line: 0, ch: 1920 }, 593 | { line: 0, ch: 1945 }, 594 | ], 595 | Schule: [{ line: 0, ch: 1929 }], 596 | erlaubt: [{ line: 0, ch: 1936 }], 597 | anderen: [{ line: 0, ch: 1954 }], 598 | Andere: [{ line: 0, ch: 1971 }], 599 | Zufriedenheitsskala: [{ line: 0, ch: 1989 }], 600 | Metrische: [{ line: 0, ch: 2014 }], 601 | Skala: [ 602 | { line: 0, ch: 2024 }, 603 | { line: 0, ch: 2471 }, 604 | ], 605 | Verhältnissskala: [{ line: 0, ch: 2043 }], 606 | definiert: [{ line: 0, ch: 2093 }], 607 | stelle: [{ line: 0, ch: 2108 }], 608 | sich: [{ line: 0, ch: 2115 }], 609 | Meter: [{ line: 0, ch: 2124 }], 610 | vor: [{ line: 0, ch: 2130 }], 611 | es: [ 612 | { line: 0, ch: 2135 }, 613 | { line: 0, ch: 4542 }, 614 | ], 615 | Abstand: [{ line: 0, ch: 2149 }], 616 | zw: [{ line: 0, ch: 2159 }], 617 | zwei: [{ line: 0, ch: 2163 }], 618 | Punkten: [{ line: 0, ch: 2168 }], 619 | berechnet: [{ line: 0, ch: 2176 }], 620 | kein: [{ line: 0, ch: 2204 }], 621 | inhaltlicher: [{ line: 0, ch: 2209 }], 622 | Nullpunkt: [{ line: 0, ch: 2222 }], 623 | lucarrowright: [ 624 | { line: 0, ch: 2233 }, 625 | { line: 0, ch: 3109 }, 626 | { line: 0, ch: 3153 }, 627 | { line: 0, ch: 3197 }, 628 | ], 629 | Einkommen: [ 630 | { line: 0, ch: 2254 }, 631 | { line: 0, ch: 2289 }, 632 | ], 633 | von: [ 634 | { line: 0, ch: 2264 }, 635 | { line: 0, ch: 3285 }, 636 | { line: 0, ch: 3750 }, 637 | ], 638 | gültiges: [{ line: 0, ch: 2280 }], 639 | Zigarettenkonsum: [{ line: 0, ch: 2364 }], 640 | Person: [{ line: 0, ch: 2387 }], 641 | Merkmalsart: [{ line: 0, ch: 2447 }], 642 | des: [{ line: 0, ch: 2584 }], 643 | Tabakkonsums: [{ line: 0, ch: 2588 }], 644 | pro: [ 645 | { line: 0, ch: 2601 }, 646 | { line: 0, ch: 2697 }, 647 | ], 648 | Tag: [ 649 | { line: 0, ch: 2605 }, 650 | { line: 0, ch: 2701 }, 651 | ], 652 | Gramm: [{ line: 0, ch: 2612 }], 653 | Stetig: [{ line: 0, ch: 2643 }], 654 | Verhältniss: [{ line: 0, ch: 2653 }], 655 | Anzahl: [{ line: 0, ch: 2669 }], 656 | gerauchte: [{ line: 0, ch: 2676 }], 657 | Zigaretten: [{ line: 0, ch: 2686 }], 658 | Diskret: [{ line: 0, ch: 2734 }], 659 | Nichtraucher: [ 660 | { line: 0, ch: 2760 }, 661 | { line: 0, ch: 2851 }, 662 | ], 663 | schwacher: [{ line: 0, ch: 2774 }], 664 | Raucher: [ 665 | { line: 0, ch: 2784 }, 666 | { line: 0, ch: 2801 }, 667 | { line: 0, ch: 2865 }, 668 | ], 669 | starker: [{ line: 0, ch: 2793 }], 670 | Ordinal: [{ line: 0, ch: 2835 }], 671 | Nominal: [{ line: 0, ch: 2926 }], 672 | Masse: [{ line: 0, ch: 2944 }], 673 | Arithmetisches: [{ line: 0, ch: 2953 }], 674 | Mittel: [ 675 | { line: 0, ch: 2968 }, 676 | { line: 0, ch: 3126 }, 677 | { line: 0, ch: 3170 }, 678 | { line: 0, ch: 3214 }, 679 | { line: 0, ch: 3278 }, 680 | { line: 0, ch: 3350 }, 681 | ], 682 | D: [{ line: 0, ch: 3037 }], 683 | xquer0: [{ line: 0, ch: 3051 }], 684 | Problem: [{ line: 0, ch: 3082 }], 685 | D1: [ 686 | { line: 0, ch: 3093 }, 687 | { line: 0, ch: 4210 }, 688 | ], 689 | D2: [ 690 | { line: 0, ch: 3137 }, 691 | { line: 0, ch: 4286 }, 692 | ], 693 | D3: [ 694 | { line: 0, ch: 3181 }, 695 | { line: 0, ch: 3296 }, 696 | { line: 0, ch: 4386 }, 697 | ], 698 | Datensätze: [{ line: 0, ch: 3237 }], 699 | alle: [{ line: 0, ch: 3254 }], 700 | arithmetisches: [{ line: 0, ch: 3263 }], 701 | Bei: [{ line: 0, ch: 3292 }], 702 | grossen: [{ line: 0, ch: 3310 }], 703 | Spikes: [{ line: 0, ch: 3319 }], 704 | im: [ 705 | { line: 0, ch: 3340 }, 706 | { line: 0, ch: 3347 }, 707 | ], 708 | gut: [{ line: 0, ch: 3343 }], 709 | repräsentiert: [{ line: 0, ch: 3357 }], 710 | Lagemasse: [{ line: 0, ch: 3376 }], 711 | Lage: [{ line: 0, ch: 3387 }], 712 | Daten: [ 713 | { line: 0, ch: 3396 }, 714 | { line: 0, ch: 4043 }, 715 | ], 716 | Verteilung: [ 717 | { line: 0, ch: 3403 }, 718 | { line: 0, ch: 3531 }, 719 | ], 720 | Zufallszahl: [{ line: 0, ch: 3420 }], 721 | eines: [{ line: 0, ch: 3434 }], 722 | Wahrscheinlichkeitsmasses: [{ line: 0, ch: 3440 }], 723 | Median: [ 724 | { line: 0, ch: 3509 }, 725 | { line: 0, ch: 3743 }, 726 | ], 727 | Halbierung: [{ line: 0, ch: 3516 }], 728 | Biespiel: [{ line: 0, ch: 3719 }], 729 | Berechne: [{ line: 0, ch: 3730 }], 730 | den: [{ line: 0, ch: 3739 }], 731 | Werten: [{ line: 0, ch: 3758 }], 732 | P: [{ line: 0, ch: 3796 }], 733 | Quantil: [{ line: 0, ch: 3799 }], 734 | Immer: [{ line: 0, ch: 3974 }], 735 | zuerst: [{ line: 0, ch: 3980 }], 736 | n: [{ line: 0, ch: 3987 }], 737 | p: [{ line: 0, ch: 3991 }], 738 | ausrechnen: [{ line: 0, ch: 3993 }], 739 | egal: [{ line: 0, ch: 4005 }], 740 | was: [{ line: 0, ch: 4010 }], 741 | gegeben: [{ line: 0, ch: 4014 }], 742 | Streuung: [{ line: 0, ch: 4031 }], 743 | Varianz: [ 744 | { line: 0, ch: 4053 }, 745 | { line: 0, ch: 4202 }, 746 | { line: 0, ch: 4278 }, 747 | { line: 0, ch: 4378 }, 748 | ], 749 | Oft: [{ line: 0, ch: 4534 }], 750 | so: [{ line: 0, ch: 4545 }], 751 | gewählt: [{ line: 0, ch: 4557 }], 752 | trotzdem: [{ line: 0, ch: 4579 }], 753 | einen: [{ line: 0, ch: 4588 }], 754 | Erwartungstreuen: [{ line: 0, ch: 4594 }], 755 | Schätzer: [{ line: 0, ch: 4611 }], 756 | brauchen: [{ line: 0, ch: 4620 }], 757 | Dann: [{ line: 0, ch: 4630 }], 758 | kommt: [{ line: 0, ch: 4635 }], 759 | Korrektur: [{ line: 0, ch: 4645 }], 760 | zum: [{ line: 0, ch: 4655 }], 761 | Zuge: [{ line: 0, ch: 4659 }], 762 | }; 763 | 764 | const testFile = ` 765 | # [[R#R|Grundbegriffe]] der [[Wahrscheinlichkeitsrechnung#Wahrscheinlichkeitsrechnung|Wahrscheinlichkeitsrechnung]] 766 | ## Statistische Einheit 767 | Beispiel: Schuhe aussuchen nach Kriterien. 768 | Man hat 4 Paare zur Auswahl -> 4 **Objekte** 769 | Die Objekte werden als **statistische Einheit** bezeichnet 770 | 771 | ## Grundgesamtheit 772 | Die Menge aller statistischer Einheiten, die für eine Untersuchung in Frage kommen. 773 | (Im obigen Beispiel: 4 Paar Schuhe) 774 | Könnte aber auch die Menge aller Schuhe sein 775 | 776 | ## Merkmale 777 | Im obigen Beispiel: Farbe, Material, Absatzhöhe usw. 778 | (Eigenschaften einer statistischen Einheit) 779 | 780 | ## Merkmalsausprägung 781 | ### Qualitativ 782 | Beispiel Farbe der Schuhe: Wenn die vier Paar Schuhe rot, blau, grün und gelb sind, hat das Merkmal "Farbe" die Ausprägung rot, blau grün und gelb. 783 | 784 | ### Quantitativ 785 | - Unterkategorien "diskret" und "stetig" 786 | 787 | Ein **diskretes** Merkmal ist ein Merkmal, das nur endlich viele Ausprägungen oder höchstens abzählbar unendlich viele Ausprägungen annehmen kann. (Zählvariablen sind stets diskret.) 788 | 789 | Ein **stetiges** Merkmal ist hingegen dadurch gekennzeichnet, dass die Ausprägungen ein Intervall bilden. 790 | 791 | Ob ein Merkmal diskret oder stetig ist, hängt nicht davon ab, wie das Merkmal in der Praxis tatsächlich angegeben wird. Die Körpergrösse ist z. B. stetig, obwohl man sie in der Praxis kaum genauer als auf volle Zentimeter gerundet ausweist. Ähnliches gilt für die Grösse einer Wohnung, die meist in vollen Quadratmetern angegeben wird 792 | 793 | # Skalenniveau 794 | - Skalenniveaus haben eine hierarchische Struktur 795 | - Schwächste, bis Beste Struktur (Bild: EG. bis 4. OG) 796 | - Die Wurzelskala ist die **Nominalskala** 797 | 798 | ![[Pasted image 20230204143047.png]] 799 | 800 | ## Nominalskala 801 | - Rangordnung fehlt (Wie soll ich die ordnen?) 802 | - Beispiele: Siehe Bild 803 | 804 | ## Ordinalskala 805 | - Rangordnung ist vorhanden. 806 | - Bestes Beispiel sind Schulnoten. (1 ist schlechter als 3 usw.) 807 | - Es gibt aber keine "sinnvollen" Abstände. (z.B. ist eine 5.1 an einer Schule erlaubt, an einer anderen nicht) 808 | - Andere Beispiele: Zufriedenheitsskala. 809 | 810 | ## Metrische Skala (Intervall-, Verhältnissskala) 811 | - Rangordnung und Abstände sind definiert (Man stelle sich ein Meter vor, es kann ein **Abstand** zw. zwei Punkten berechnet werden) 812 | - Es gibt kein inhaltlicher Nullpunkt :luc_arrow_right: Ein Einkommen von "0" ist ein gültiges Einkommen. 813 | - Beispiele: Siehe Bild 814 | $$$ fvsf $$ 815 | ### Beispiel 816 | #assessment/ws 817 | Zigarettenkonsum einer Person 818 | | Ausprägung | Merkmalsart | Skala | 819 | | ------------------------------------------------ | --------------------- | ----------- | 820 | | Menge des Tabakkonsums pro Tag in Gramm | Quantitativ & Stetig | Verhältniss | 821 | | Anzahl gerauchte Zigaretten pro Tag | Quantitativ & Diskret | Intervall | 822 | | Nichtraucher, schwacher Raucher, starker Raucher | Qualitativ | Ordinal | 823 | | Nichtraucher, Raucher | Qualitativ | Nominal | 824 | 825 | # Masse 826 | ## Arithmetisches Mittel 827 | $$\LARGE 828 | \bar{x} = \frac{1}{n}\sum_{i=1}^n x_i 829 | $$ 830 | **Beispiel:** 831 | - D = 1,2,4,9 832 | - x_quer(0) = **(1+2+4+9)/4** 833 | 834 | **Problem:** 835 | D1 = 5,5,5,5,5 :luc_arrow_right: Mittel = 5 836 | D2 = 3,4,5,6,7 :luc_arrow_right: Mittel = 5 837 | D3 = 1,2,5,8,9 :luc_arrow_right: Mittel = 5 838 | 839 | Die obigen Datensätze haben alle ein arithmetisches Mittel von 5. Bei D3 werden die grossen "Spikes" (1, 9) nicht im gut im Mittel repräsentiert. 840 | 841 | ## Lagemasse (Lage der Daten) 842 | Verteilung einer Zufallszahl / eines Wahrscheinlichkeitsmasses. 843 | 844 | ![[Pasted image 20230204152906.png]] 845 | ### Median 846 | Halbierung der Verteilung 847 | $$\LARGE 848 | M_{d}= 849 | \begin{cases} 850 | x_{(\frac{n+1}{2})} \text{ falls n ungerade} \\ 851 | \frac{x_{(\frac{n}{2})} + x_{(\frac{n}{2} + 1)}}{2} \text{ falls n gerade} 852 | \end{cases} 853 | $$ 854 | #assessment/ws 855 | *Biespiel*: Berechne den Median von 185 Werten. ↪️ (185+1) / 2 ↪️ **93** 856 | 857 | ### P% Quantil 858 | **Beispiele** 859 | 860 | $$ 861 | D = \{9,2,7,8,11\} 862 | $$$$ 863 | Q_{25\%} = n * p = 5 * 0.25 = 1.25 864 | $$ 865 | $$ 866 | Q_{50\%} = Median-Formel ungerade = x_{(\frac{n+1}{2})} = \frac{6}{2} = 3 = D[3] = 7 867 | $$ 868 | 869 | Immer zuerst n * p ausrechnen, egal was gegeben ist. 870 | 871 | ## Streuung in Daten 872 | ### Varianz 873 | $$\LARGE 874 | x = \frac{1}{n}\sum_{i=1}^n (x_i-\bar{x 875 | })^2 876 | $$ 877 | Beispiele 878 | $$ 879 | D_{1}= {1,1,1,1} 880 | $$ 881 | $$ 882 | D_{2}= {2,4,6,8} 883 | $$ 884 | $$ 885 | D_{3}= a, a+1, a+2, a+3 886 | $$ 887 | Varianz D1 888 | $$ 889 | s^2_{D_{1}} = \frac{(1-1)^2+(1-1)^2+(1-1)^2+(1-1)^2}{4} = 0 890 | $$ 891 | Varianz D2 892 | $$ 893 | \bar{x}_{D_{2}} = 5 894 | $$ 895 | $$ 896 | s^2{D_{2}} = \frac{(2-5)^2+(4-5)^2+(6-5)^2+(8-5)^2}{4} = 4 897 | $$ 898 | Varianz D3 899 | $$ 900 | s^2{D_{3}} = \frac{1}{4}*((a-(a+\frac{3}{2})^2 + (a+1-(a+\frac{3}{2})^2) + ... + (a+3-(a+\frac{3}{2})^2 901 | $$ 902 | 903 | ![[Pasted image 20230401142915.png]] 904 | 905 | Oft ist es so, dass 1) gewählt wird, und man trotzdem einen Erwartungstreuen Schätzer brauchen. Dann kommt die Korrektur zum Zuge. 906 | `; 907 | -------------------------------------------------------------------------------- /src/services/tokenizationService.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { Editor, EditorPosition } from 'obsidian'; 14 | 15 | export type WordLookup = { [key: string]: EditorPosition[] }; 16 | 17 | const OBSIDIAN_METADATA_REGEX = /^\n*?---[\s\S]+?---/g; 18 | const OBSIDIAN_TAG_REGEX = /#+([a-zA-Z0-9_/]+)/g; 19 | const OBSIDIAN_LINKS_REGEX = /\[([^\]]+)\]+/g; 20 | 21 | const HTML_COMMENT_REGEX = //g; 22 | const HTML_TAG_REGEX = /<\/?[\w\s="/.':;#-/?]+>/gm; 23 | 24 | const MARKDOWN_LATEX_BLOCK_REGEX = /\$\$([^$]+)\$\$/g; 25 | const MARKDOWN_LATEX_INLINE_REGEX = /\$([^$]+)\$/g; 26 | const MARKDOWN_LINKS_AND_IMAGES_REGEX = /!?\[([^\]]+)\]\((?:<.*>)?\s*([^\s)]+)\s*\)/gm; 27 | const MARKDOWN_CODE_BLOCK_REGEX = /```[\s\S]+?```/g; 28 | const MARKDOWN_ASTERISK_EMPHASIS_REGEX = /([*]+)(\S)(.*?\S)??(\1)/g; // g1 = *, g2 = first char, g3 = middle, g4 = * 29 | 30 | // const MARKDOWN_LODASH_EMPHASIS_REGEX = /(^|\W)([_]+)(\S)(.*?\S)??\2($|\W)/g; 31 | // const MARKDOWN_CODE_INLINE_REGEX = /`(.+?)`/g; 32 | // const MARKDOWN_STRIKETROUGH_REGEX = /~(.*?)~/g; 33 | 34 | export class CrossbowTokenizationService { 35 | private readonly SKIP_REGEX = /\s/; 36 | 37 | public getWordLookupFromEditor(targetEditor: Editor): WordLookup { 38 | if (!targetEditor) return {}; 39 | 40 | const wordLookup: WordLookup = {}; 41 | 42 | const rawText = targetEditor.getValue(); 43 | const plainText = CrossbowTokenizationService.redactText(rawText); 44 | 45 | for (let i = 0; i < plainText.length; i++) { 46 | if (plainText[i].match(this.SKIP_REGEX)) continue; 47 | else { 48 | let word = ''; 49 | const pos = targetEditor.offsetToPos(i); 50 | 51 | while (plainText[i] && !plainText[i].match(this.SKIP_REGEX)) word += plainText[i++]; 52 | 53 | const cleanWord = CrossbowTokenizationService.cleanWord(word); 54 | if (cleanWord.length <= 0) continue; 55 | 56 | // Offset the word start pos if the 'cleaning' of the word removed characters 57 | const wordStartOffset = word.indexOf(cleanWord[0]); 58 | if (wordStartOffset > 0) pos.ch += wordStartOffset; 59 | 60 | if (cleanWord in wordLookup) wordLookup[cleanWord].push(pos); 61 | else wordLookup[cleanWord] = [pos]; 62 | } 63 | } 64 | 65 | return wordLookup; 66 | } 67 | 68 | public static muteString = (str: string): string => str.replace(/[^\r\n]+/g, (m) => ' '.repeat(m.length)); 69 | 70 | public static muteWord = (word: string): string => ' '.repeat(word.length); 71 | 72 | public static redactText(text: string): string { 73 | // Order matters here 74 | return text 75 | .replace(MARKDOWN_ASTERISK_EMPHASIS_REGEX, (m, g1, g2, g3) => this.muteWord(g1) + g2 + g3 + this.muteWord(g1)) 76 | .replace(MARKDOWN_CODE_BLOCK_REGEX, (m) => this.muteString(m)) 77 | .replace(MARKDOWN_LATEX_BLOCK_REGEX, (m) => this.muteString(m)) 78 | .replace(MARKDOWN_LATEX_INLINE_REGEX, (m) => this.muteString(m)) 79 | .replace(MARKDOWN_LINKS_AND_IMAGES_REGEX, (m) => this.muteString(m)) 80 | .replace(OBSIDIAN_METADATA_REGEX, (m) => this.muteString(m)) 81 | .replace(OBSIDIAN_TAG_REGEX, (m) => this.muteString(m)) 82 | .replace(OBSIDIAN_LINKS_REGEX, (m) => this.muteString(m)) 83 | .replace(HTML_COMMENT_REGEX, (m) => this.muteString(m)) 84 | .replace(HTML_TAG_REGEX, (m) => this.muteString(m)); 85 | } 86 | 87 | public static cleanWord(word: string): string { 88 | return word 89 | .replace(/[^a-z0-9äöü'-]/gi, '') // Remove all non-alphanumeric characters except hyphens and apostrophes 90 | .replace(/^[’'-]+|[’'-]+$/gi, ''); // Remove leading and trailing hyphens and apostrophes 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/services/utilsService.test.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { CrossbowUtilsService } from './utilsService'; 14 | 15 | const proto = CrossbowUtilsService.prototype; 16 | 17 | describe(CrossbowUtilsService.constructor.name, () => { 18 | describe(`${proto.toArrayOfPaths.name}()`, () => { 19 | it(`should return an empty array`, () => { 20 | const service = new CrossbowUtilsService(); 21 | expect(service.toArrayOfPaths('')).toEqual([]); 22 | expect(service.toArrayOfPaths(' ')).toEqual([]); 23 | }); 24 | 25 | it(`should return an array with one element`, () => { 26 | const service = new CrossbowUtilsService(); 27 | expect(service.toArrayOfPaths('test')).toEqual(['test/']); 28 | expect(service.toArrayOfPaths(' test ')).toEqual(['test/']); 29 | expect(service.toArrayOfPaths('test/')).toEqual(['test/']); 30 | expect(service.toArrayOfPaths(' test/ ')).toEqual(['test/']); 31 | expect(service.toArrayOfPaths('/test')).toEqual(['test/']); 32 | expect(service.toArrayOfPaths('/test/')).toEqual(['test/']); 33 | expect(service.toArrayOfPaths(' /test/ ')).toEqual(['test/']); 34 | }); 35 | 36 | it(`should treat multiple commas as one`, () => { 37 | const service = new CrossbowUtilsService(); 38 | expect(service.toArrayOfPaths('test1,,test2')).toEqual(['test1/', 'test2/']); 39 | expect(service.toArrayOfPaths(' test1 ,,,,,,, test2 ')).toEqual(['test1/', 'test2/']); 40 | }); 41 | 42 | it(`should return an array with two elements`, () => { 43 | const service = new CrossbowUtilsService(); 44 | expect(service.toArrayOfPaths('test1,test2')).toEqual(['test1/', 'test2/']); 45 | expect(service.toArrayOfPaths(' test1 , test2 ')).toEqual(['test1/', 'test2/']); 46 | expect(service.toArrayOfPaths('test1/,test2/')).toEqual(['test1/', 'test2/']); 47 | expect(service.toArrayOfPaths(' test1/ , test2/ ')).toEqual(['test1/', 'test2/']); 48 | expect(service.toArrayOfPaths('/test1,/test2')).toEqual(['test1/', 'test2/']); 49 | expect(service.toArrayOfPaths('/test1/,/test2/')).toEqual(['test1/', 'test2/']); 50 | expect(service.toArrayOfPaths(' /test1/ , /test2/ ')).toEqual(['test1/', 'test2/']); 51 | }); 52 | 53 | it(`should handle nested paths`, () => { 54 | const service = new CrossbowUtilsService(); 55 | expect(service.toArrayOfPaths('test1/test2')).toEqual(['test1/test2/']); 56 | expect(service.toArrayOfPaths(' test1 / test2 ')).toEqual(['test1 / test2/']); 57 | expect(service.toArrayOfPaths('test1/test2/')).toEqual(['test1/test2/']); 58 | expect(service.toArrayOfPaths(' test1 / test2/ ')).toEqual(['test1 / test2/']); 59 | expect(service.toArrayOfPaths('/test1/test2')).toEqual(['test1/test2/']); 60 | expect(service.toArrayOfPaths('/test1/test2/')).toEqual(['test1/test2/']); 61 | expect(service.toArrayOfPaths(' /test1/ /test2/ ')).toEqual(['test1/ /test2/']); 62 | }); 63 | }); 64 | 65 | describe(`${proto.toWordList.name}()`, () => { 66 | it(`should return an empty array`, () => { 67 | const service = new CrossbowUtilsService(); 68 | expect(service.toWordList('')).toEqual([]); 69 | expect(service.toWordList(' ')).toEqual([]); 70 | }); 71 | 72 | it(`should return an array with one element`, () => { 73 | const service = new CrossbowUtilsService(); 74 | expect(service.toWordList('test')).toEqual(['test']); 75 | expect(service.toWordList(' test ')).toEqual(['test']); 76 | }); 77 | 78 | it(`should treat multiple commas as one`, () => { 79 | const service = new CrossbowUtilsService(); 80 | expect(service.toWordList('test1,,test2')).toEqual(['test1', 'test2']); 81 | expect(service.toWordList(' test1 ,,,,,,, test2 ')).toEqual(['test1', 'test2']); 82 | }); 83 | 84 | it(`should return an array with multiple elements`, () => { 85 | const service = new CrossbowUtilsService(); 86 | expect(service.toWordList('test1,test2')).toEqual(['test1', 'test2']); 87 | expect(service.toWordList(' test1 , test2 ')).toEqual(['test1', 'test2']); 88 | }); 89 | 90 | it(`should not manipulate the input and not trip on special characters`, () => { 91 | const service = new CrossbowUtilsService(); 92 | // List with chinese characters 93 | expect(service.toWordList('test1,测试2')).toEqual(['test1', '测试2']); 94 | // List with special characters 95 | expect(service.toWordList('test1,测试2,~!@#$%^&*()_+')).toEqual(['test1', '测试2', '~!@#$%^&*()_+']); 96 | // List with emojis 97 | expect(service.toWordList('test1,测试2,😀😁😂🤣😃😄😅😆😉😊')).toEqual([ 98 | 'test1', 99 | '测试2', 100 | '😀😁😂🤣😃😄😅😆😉😊', 101 | ]); 102 | }); 103 | }); 104 | }); 105 | -------------------------------------------------------------------------------- /src/services/utilsService.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | export class CrossbowUtilsService { 14 | // folders names (or paths, separated by "/"). (Whitepaces around commas will be trimmed) 15 | public toArrayOfPaths(pathArrayLike: string): string[] { 16 | return pathArrayLike 17 | .replace(/,*\s*$/, '') // Remove trailing comma 18 | .replace(/,{2,}/g, ',') // Remove n > 1 chained commas 19 | .split(',') 20 | .map((folderOrPath) => folderOrPath.trim()) 21 | .filter((folderOrPath) => folderOrPath.length > 0) // Remove empty strings 22 | .map((folderOrPath) => folderOrPath.replace(/^\/+/, '')) // Remove leading slashes 23 | .map((folderOrPath) => folderOrPath.replace(/\/{2,}/g, '/')) // Remove n > 1 chained slashes 24 | .map((folderOrPath) => (folderOrPath.endsWith('/') ? folderOrPath : `${folderOrPath}/`)); // Add trailing slash 25 | } 26 | 27 | // case-sensitive, comma separated list of word. (Whitepaces around commas will be trimmed 28 | public toWordList(wordArrayLike: string): string[] { 29 | return wordArrayLike 30 | .replace(/,*\s*$/, '') // Remove trailing comma 31 | .replace(/,{2,}/g, ',') // Remove n > 1 chained commas 32 | .split(',') 33 | .map((word) => word.trim()) 34 | .filter((folderOrPath) => folderOrPath.length > 0); // Remove empty strings 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/settings.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { App, PluginSettingTab, Setting } from 'obsidian'; 14 | import CrossbowPlugin from './main'; 15 | import { CrossbowPluginSettings, CrossbowSettingsService } from './services/settingsService'; 16 | import { CrossbowUtilsService } from './services/utilsService'; 17 | 18 | export class CrossbowSettingTab extends PluginSettingTab { 19 | constructor( 20 | app: App, 21 | plugin: CrossbowPlugin, 22 | private settingsService: CrossbowSettingsService, 23 | private utilsService: CrossbowUtilsService 24 | ) { 25 | super(app, plugin); 26 | } 27 | 28 | display(): void { 29 | const { containerEl } = this; 30 | 31 | containerEl.empty(); 32 | containerEl.createEl('h2', { text: 'Crossbow Settings 🏹' }); 33 | 34 | this.addIndexingSettings(containerEl); 35 | this.addSuggestionsSettings(containerEl); 36 | this.addAutoRefreshSettings(containerEl); 37 | this.addLoggingSettings(containerEl); 38 | } 39 | 40 | private addIndexingSettings(containerEl: HTMLElement) { 41 | containerEl.createEl('h3', { text: 'Indexing' }); 42 | 43 | new Setting(containerEl) 44 | .setName('Ignored Vault Folders') 45 | .setDesc( 46 | 'A case-sensitive, comma separated list of folders (or paths, separated by "/") to ignore when indexing. (Whitepaces around commas will be trimmed)' 47 | ) 48 | .addTextArea((textArea) => { 49 | textArea 50 | .setValue(this.settingsService.getSettings().ignoreVaultFolders?.join(', ') ?? '') 51 | .onChange( 52 | async (value) => 53 | await this.updateSettingValue('ignoreVaultFolders', this.utilsService.toArrayOfPaths(value)) 54 | ); 55 | 56 | textArea.inputEl.setAttr('style', 'height: 10vh; width: 25vw;'); 57 | }); 58 | } 59 | 60 | private addSuggestionsSettings(containerEl: HTMLElement) { 61 | containerEl.createEl('h3', { text: 'Suggestions' }); 62 | 63 | new Setting(containerEl) 64 | .setName('Ignored Words') 65 | .setDesc( 66 | 'A case-sensitive, comma separated list of words to ignore when searching for items (Headers, tags). (Whitepaces around commas will be trimmed)' 67 | ) 68 | .addTextArea((textArea) => { 69 | textArea 70 | .setValue(this.settingsService.getSettings().ignoredWordsCaseSensisitve?.join(', ') ?? '') 71 | .onChange( 72 | async (value) => 73 | await this.updateSettingValue('ignoredWordsCaseSensisitve', this.utilsService.toWordList(value)) 74 | ); 75 | 76 | textArea.inputEl.setAttr('style', 'height: 10vh; width: 25vw;'); 77 | }); 78 | 79 | new Setting(containerEl) 80 | .setName('Ignore occurrences which start with a lowercase letter') 81 | .setDesc( 82 | 'If checked, occurrences (Words in the active editor) which start with a lowercase letter will be ignored' 83 | ) 84 | .addToggle((toggle) => 85 | toggle 86 | .setValue(this.settingsService.getSettings().ignoreOccurrencesWhichStartWithLowercaseLetter) 87 | .onChange( 88 | async (value) => await this.updateSettingValue('ignoreOccurrencesWhichStartWithLowercaseLetter', value) 89 | ) 90 | ); 91 | 92 | new Setting(containerEl) 93 | .setName('Ignore suggestions which start with a lowercase letter') 94 | .setDesc('If checked, suggestions which start with a lowercase letter will be ignored') 95 | .addToggle((toggle) => 96 | toggle 97 | .setValue(this.settingsService.getSettings().ignoreSuggestionsWhichStartWithLowercaseLetter) 98 | .onChange( 99 | async (value) => await this.updateSettingValue('ignoreSuggestionsWhichStartWithLowercaseLetter', value) 100 | ) 101 | ); 102 | 103 | new Setting(containerEl) 104 | .setName('Make suggestions to items in the same file') 105 | .setDesc('If checked, suggestions to items (Headers, Tags) in the same file be created') 106 | .addToggle((toggle) => 107 | toggle 108 | .setValue(this.settingsService.getSettings().suggestInSameFile) 109 | .onChange(async (value) => await this.updateSettingValue('suggestInSameFile', value)) 110 | ); 111 | 112 | new Setting(containerEl) 113 | .setName('Minimum word length of suggestions') 114 | .setDisabled(!this.settingsService.getSettings().useAutoRefresh) 115 | .setDesc('Defines the min. length an item (Header, File, Tag) must have for it to be considered a suggestion') 116 | .addSlider((slider) => { 117 | slider 118 | .setLimits(1, 20, 1) 119 | .setValue(this.settingsService.getSettings().minimumSuggestionWordLength) 120 | .onChange(async (value) => await this.updateSettingValue('minimumSuggestionWordLength', value)) 121 | .setDynamicTooltip(); 122 | }); 123 | } 124 | 125 | private addLoggingSettings(containerEl: HTMLElement) { 126 | containerEl.createEl('h3', { text: 'Debug' }); 127 | 128 | new Setting(containerEl) 129 | .setName('Enable logging') 130 | .setDesc('If checked, debug logs will be printed to the console') 131 | .addToggle((toggle) => 132 | toggle 133 | .setValue(this.settingsService.getSettings().useLogging) 134 | .onChange(async (value) => await this.updateSettingValue('useLogging', value)) 135 | ); 136 | } 137 | 138 | private addAutoRefreshSettings(containerEl: HTMLElement) { 139 | containerEl.createEl('h3', { text: 'Auto refresh' }); 140 | 141 | const autoRefreshSetting = new Setting(containerEl) 142 | .setName('Enable auto refresh') 143 | .setDesc('If checked, crossbow will automatically refresh if the current note has been edited'); 144 | 145 | const autoRefreshDelaySetting = new Setting(containerEl) 146 | .setName('Auto refresh delay') 147 | .setDesc('A delay in ms after which crossbow will refresh if the current note has been edited'); 148 | 149 | let autoRefreshSettingUpdateTimeout: ReturnType | undefined = undefined; 150 | 151 | autoRefreshSetting.addToggle((toggle) => 152 | toggle.setValue(this.settingsService.getSettings().useAutoRefresh).onChange(async (value) => { 153 | autoRefreshDelaySetting.setDisabled(!value); 154 | await this.updateSettingValue('useAutoRefresh', value); 155 | }) 156 | ); 157 | 158 | autoRefreshDelaySetting.addSlider((slider) => { 159 | slider 160 | .setLimits(2600, 20000, 100) 161 | .setValue(this.settingsService.getSettings().autoRefreshDelayMs) 162 | .onChange(async (value) => { 163 | if (autoRefreshSettingUpdateTimeout) { 164 | clearTimeout(autoRefreshSettingUpdateTimeout); 165 | } 166 | 167 | autoRefreshSettingUpdateTimeout = setTimeout(async () => { 168 | await this.updateSettingValue('autoRefreshDelayMs', value); 169 | }, 1000); 170 | }) 171 | .setDynamicTooltip(); 172 | }); 173 | } 174 | 175 | private updateSettingValue = async ( 176 | key: K, 177 | value: CrossbowPluginSettings[K] 178 | ) => { 179 | const settings = this.settingsService.getSettings(); 180 | settings[key] = value; 181 | await this.settingsService.saveSettings(settings); 182 | }; 183 | } 184 | -------------------------------------------------------------------------------- /src/view/tree/tree.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { Editor } from 'obsidian'; 14 | import { ITreeNodeData, TreeNode } from './treeNode'; 15 | import { TreeUpdater } from './treeUpdater'; 16 | 17 | export const registerTreeElements = (): void => { 18 | TreeNode.register(); 19 | Tree.register(); 20 | }; 21 | 22 | export type ITreeContextProvider = { 23 | readonly targetEditor: Editor; 24 | }; 25 | 26 | export class Tree extends HTMLElement implements ITreeContextProvider { 27 | public readonly targetEditor: Editor; 28 | private readonly treeUpdater: TreeUpdater; 29 | 30 | public constructor(targetEditor: Editor) { 31 | super(); 32 | this.targetEditor = targetEditor; 33 | this.treeUpdater = new TreeUpdater(); 34 | } 35 | 36 | public static register(): void { 37 | if (!customElements.get('crossbow-tree')) { 38 | customElements.define('crossbow-tree', Tree); 39 | } 40 | } 41 | 42 | public update(data: T[]): void { 43 | const oldNodes = this.getChildTreeNodes(); 44 | const batch = this.treeUpdater.update( 45 | data.map((d) => new TreeNode(d, this)), 46 | oldNodes 47 | ); 48 | 49 | requestAnimationFrame(() => { 50 | batch.forEach((update) => update(this)); 51 | }); 52 | } 53 | 54 | private getChildTreeNodes(): TreeNode[] { 55 | return this.children.length > 0 ? (Array.from(this.children) as TreeNode[]) : []; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/view/tree/treeNode.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { ButtonComponent, Editor, getIcon } from 'obsidian'; 14 | import { ITreeContextProvider } from './tree'; 15 | import { IComparable } from './treeUpdater'; 16 | 17 | export enum TreeItemButtonIcon { 18 | Scroll = 'lucide-scroll', 19 | Inspect = 'lucide-inspect', 20 | Search = 'lucide-search', 21 | } 22 | 23 | export interface ITreeNodeContext { 24 | targetEditor: Editor; 25 | self: TreeNode; 26 | } 27 | 28 | export interface ITreeNodeData extends IComparable { 29 | readonly parent: ITreeNodeData | null; 30 | readonly children?: ITreeNodeData[]; 31 | 32 | get text(): string; 33 | get suffix(): string | null; 34 | get flair(): string | null; 35 | get subtitle(): string | null; 36 | get actions(): { 37 | name: string; 38 | icon: TreeItemButtonIcon; 39 | callback(this: ITreeNodeData, ev: MouseEvent, ctx: ITreeNodeContext): void; 40 | }[]; 41 | 42 | onClick?(this: ITreeNodeData, ctx: ITreeNodeContext): void; 43 | } 44 | 45 | export class TreeNode extends HTMLElement { 46 | private readonly manager: ITreeContextProvider; 47 | protected readonly childrenWrapper: HTMLDivElement | null = null; 48 | private readonly iconWrapper: HTMLDivElement | null = null; 49 | private readonly inner: HTMLDivElement; 50 | private readonly mainWrapper: HTMLDivElement; 51 | private readonly flairWrapper: HTMLDivElement; 52 | private suffix: HTMLSpanElement; 53 | private subtitle: HTMLSpanElement; 54 | private flair: HTMLSpanElement; 55 | private buttons: ButtonComponent[] = []; 56 | public readonly value: TData; 57 | 58 | public constructor(value: TData, manager: ITreeContextProvider) { 59 | super(); 60 | 61 | this.value = value; 62 | this.manager = manager; 63 | const isLeaf = this.value.children === undefined; 64 | 65 | this.addClass('tree-item'); 66 | 67 | this.mainWrapper = this.createDiv({ 68 | cls: 'tree-item-self is-clickable mod-collapsible', 69 | }); 70 | 71 | if (!isLeaf) { 72 | this.iconWrapper = this.mainWrapper.createDiv({ 73 | cls: 'tree-item-icon collapse-icon is-collapsed', 74 | }); 75 | this.iconWrapper.appendChild(getIcon('right-triangle') ?? new SVGElement()); 76 | } 77 | 78 | this.inner = this.mainWrapper.createDiv({ 79 | cls: 'tree-item-inner cb-tree-item-inner-extensions', 80 | text: this.value.text, 81 | }); 82 | 83 | if (this.value.flair !== null) { 84 | this.flairWrapper = this.mainWrapper.createDiv({ 85 | cls: 'tree-item-flair-outer', 86 | }); 87 | this.flair = this.flairWrapper.createEl('span', { 88 | cls: 'tree-item-flair', 89 | text: this.value.flair, 90 | }); 91 | } 92 | 93 | if (this.value.suffix !== null) { 94 | this.suffix = this.inner.createSpan({ 95 | cls: 'cb-tree-item-inner-suffix', 96 | text: this.value.suffix, 97 | }); 98 | } 99 | 100 | if (this.value.subtitle !== null) { 101 | this.subtitle = this.inner.createEl('span', { 102 | cls: 'cb-tree-item-inner-subtitle', 103 | text: this.value.subtitle, 104 | }); 105 | } 106 | 107 | if (this.value.onClick !== undefined) { 108 | const boundOnClick = this.value.onClick.bind(this.value); 109 | this.mainWrapper.addEventListener('click', () => boundOnClick(this.context())); 110 | } 111 | 112 | if (!isLeaf) { 113 | this.childrenWrapper = this.createDiv({ cls: 'tree-item-children' }); 114 | this.childrenWrapper.style.display = 'none'; 115 | 116 | // collapse / expand 117 | this.mainWrapper.addEventListener('click', () => (this.isCollapsed() ? this.expand() : this.collapse())); 118 | 119 | // lazy-create children nodes 120 | this.mainWrapper.addEventListener('click', () => this.generateChildren(), { once: true }); 121 | } 122 | 123 | if (this.value.actions.length > 0) { 124 | this.value.actions.forEach((action) => { 125 | const boundCallback = action.callback.bind(this.value); 126 | this.addButton(action.name, action.icon, (ev) => boundCallback(ev, this.context())); 127 | }); 128 | } 129 | } 130 | 131 | public get childTreeNodes(): TreeNode[] { 132 | return this.childrenWrapper ? (Array.from(this.childrenWrapper.children) as TreeNode[]) : []; 133 | } 134 | 135 | public static register(): void { 136 | if (!customElements.get('crossbow-tree-item')) { 137 | customElements.define('crossbow-tree-item', TreeNode); 138 | } 139 | } 140 | 141 | public context(): ITreeNodeContext { 142 | return { 143 | targetEditor: this.manager.targetEditor, 144 | self: this, 145 | }; 146 | } 147 | 148 | public generateChildren(): void { 149 | if (!this.childrenWrapper || !this.value.children) return; 150 | if (this.childrenWrapper.children.length > 0) return; 151 | 152 | const nodes = this.value.children.map((child) => new TreeNode(child, this.manager)); 153 | this.childrenWrapper.replaceChildren(...nodes); 154 | } 155 | 156 | public isCollapsed() { 157 | if (!this.childrenWrapper || !this.iconWrapper) return true; 158 | 159 | return this.iconWrapper.hasClass('is-collapsed'); 160 | } 161 | 162 | public expand() { 163 | if (!this.childrenWrapper || !this.iconWrapper) return; 164 | 165 | this.iconWrapper.removeClass('is-collapsed'); 166 | this.childrenWrapper.style.display = 'block'; 167 | } 168 | 169 | public collapse() { 170 | if (!this.childrenWrapper || !this.iconWrapper) return; 171 | 172 | this.iconWrapper.addClass('is-collapsed'); 173 | this.childrenWrapper.style.display = 'none'; 174 | } 175 | 176 | public setDisable() { 177 | this.mainWrapper.style.textDecoration = 'line-through'; 178 | this.mainWrapper.style.color = 'var(--text-muted)'; 179 | this.style.cursor = 'wait'; 180 | 181 | this.buttons.forEach((button) => { 182 | button.setDisabled(true); 183 | button.disabled = true; 184 | }); 185 | 186 | this.childTreeNodes.forEach((child) => child.setDisable()); 187 | } 188 | 189 | public addButton( 190 | label: string, 191 | iconName: TreeItemButtonIcon, 192 | onclick: (this: HTMLDivElement, ev: MouseEvent) => void 193 | ): void { 194 | const button = new ButtonComponent(this.mainWrapper); 195 | 196 | button.setTooltip(label); 197 | button.setIcon(iconName); 198 | button.setClass('cb-tree-item-button'); 199 | button.onClick(onclick); 200 | 201 | this.buttons.push(button); 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /src/view/tree/treeUpdater.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { ITreeNodeData, TreeNode } from './treeNode'; 14 | 15 | export interface IComparable { 16 | uid: string; 17 | } 18 | 19 | export const equals = (a: IComparable, b: IComparable): boolean => a.uid === b.uid; 20 | 21 | export type BatchUpdate = ((container: HTMLElement) => void)[]; 22 | 23 | export class TreeUpdater { 24 | public update(newNodes: TreeNode[], oldNodes: TreeNode[]): BatchUpdate { 25 | const updates: BatchUpdate = []; 26 | 27 | for (let i = 0; i < newNodes.length; i++) { 28 | const newNode = newNodes[i]; 29 | const index = oldNodes.findIndex((oldNode) => equals(oldNode.value, newNode.value)); 30 | const existingNode = index !== -1 ? oldNodes.splice(index, 1)[0] : undefined; 31 | 32 | if (existingNode) { 33 | // Toggle expanded state of children, if it was expanded before 34 | existingNode.childTreeNodes 35 | .filter((child) => !child.isCollapsed()) 36 | .forEach((expandedChild) => { 37 | const child = newNode.childTreeNodes.find((child) => equals(child.value, expandedChild.value)); 38 | if (child) { 39 | child.expand(); 40 | child.generateChildren(); 41 | } 42 | }); 43 | 44 | // Replace existing node with new node 45 | updates.push((container) => { 46 | container.insertAfter(newNode, existingNode); 47 | 48 | if (!existingNode.isCollapsed()) { 49 | newNode.expand(); 50 | newNode.generateChildren(); 51 | } 52 | 53 | existingNode.remove(); 54 | }); 55 | } else { 56 | // Insert the new suggestion at the correct position. They are sorted by localeCompare of their 'hash' property 57 | const insertionIndex = oldNodes.findIndex((oldNode) => newNode.value.uid.localeCompare(oldNode.value.uid) < 0); 58 | 59 | updates.push((container) => { 60 | if (insertionIndex === -1) { 61 | container.appendChild(newNode); 62 | } else { 63 | container.insertBefore(newNode, oldNodes[insertionIndex]); 64 | } 65 | }); 66 | } 67 | } 68 | 69 | // Now, we're left with the existing suggestions that we need to remove 70 | updates.push((container) => { 71 | oldNodes.forEach((item) => { 72 | item.remove(); 73 | }); 74 | }); 75 | 76 | return updates; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/view/view.ts: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2023 - shoedler - github.com/shoedler 2 | // 3 | // This program is free software: you can redistribute it and/or modify 4 | // it under the terms of the GNU General Public License as published by 5 | // the Free Software Foundation, either version 3 of the License, or 6 | // (at your option) any later version. 7 | // 8 | // This program is distributed in the hope that it will be useful, 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | // GNU General Public License for more details. 12 | 13 | import { ButtonComponent, Editor, ItemView, WorkspaceLeaf } from 'obsidian'; 14 | import { CrossbowViewController } from 'src/controllers/viewController'; 15 | import { Suggestion } from 'src/model/suggestion'; 16 | import { Tree } from './tree/tree'; 17 | 18 | export class CrossbowView extends ItemView { 19 | public static viewType = 'crossbow-toolbar'; 20 | private readonly controlsContainer: HTMLDivElement; 21 | private readonly manualRefreshButton: ButtonComponent; 22 | private readonly treeContainer: HTMLDivElement; 23 | private tree: Tree | null = null; 24 | 25 | constructor(leaf: WorkspaceLeaf, private readonly onManualRefreshButtonClick: (evt: MouseEvent) => void) { 26 | super(leaf); 27 | 28 | this.controlsContainer = this.contentEl.createDiv({ cls: 'cb-view-controls' }); 29 | this.treeContainer = this.contentEl.createDiv({ cls: 'cb-view-tree' }); 30 | this.treeContainer.createSpan({ text: 'Open a note to run crossbow', cls: 'cb-view-empty' }); 31 | 32 | this.manualRefreshButton = this.createManualRefreshButton(this.controlsContainer, this.onManualRefreshButtonClick); 33 | } 34 | 35 | public getViewType(): string { 36 | return CrossbowView.viewType; 37 | } 38 | 39 | public getDisplayText(): string { 40 | return 'Crossbow'; 41 | } 42 | 43 | public getIcon(): string { 44 | return 'crossbow'; 45 | } 46 | 47 | public load(): void { 48 | super.load(); 49 | this.navigation = false; 50 | } 51 | 52 | public clear(): void { 53 | this.tree?.remove(); 54 | this.tree = null; 55 | } 56 | 57 | public update(suggestions: Suggestion[], targetEditor: Editor, showManualRefreshButton: boolean): void { 58 | showManualRefreshButton ? this.manualRefreshButton.buttonEl.show() : this.manualRefreshButton.buttonEl.hide(); 59 | 60 | if (!this.tree) { 61 | this.createTree(targetEditor); 62 | } else if (this.tree.targetEditor !== targetEditor) { 63 | this.tree.remove(); 64 | this.createTree(targetEditor); 65 | } 66 | 67 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion 68 | this.tree!.update(suggestions); 69 | } 70 | 71 | private createTree(targetEditor: Editor) { 72 | this.tree = new Tree(targetEditor); 73 | this.treeContainer.empty(); 74 | this.treeContainer.appendChild(this.tree); 75 | } 76 | 77 | private createManualRefreshButton(parentEl: HTMLElement, onClick: (ev: MouseEvent) => void): ButtonComponent { 78 | const button = new ButtonComponent(parentEl); 79 | 80 | button.buttonEl.id = CrossbowViewController.MANUAL_REFRESH_BUTTON_ID; 81 | button.setTooltip('Refresh suggestions'); 82 | button.setIcon('lucide-rotate-cw'); 83 | button.setClass('cb-tree-item-button'); 84 | button.onClick(onClick); 85 | 86 | return button; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 1 | .cb-tree-item-inner-extensions { 2 | word-break: break-word; 3 | margin-right: auto; /* To make sure the buttons are on the right */ 4 | } 5 | 6 | .cb-tree-item-inner-suffix { 7 | margin-left: 0.2rem; 8 | font-size: var(--font-smallest); 9 | color: var(--text-muted); 10 | padding: 0.2rem; 11 | padding-top: 0rem; 12 | padding-bottom: 0.1rem; 13 | background-color: var(--color-base-30); 14 | border-radius: 1rem; 15 | } 16 | 17 | .cb-tree-item-inner-subtitle { 18 | display: block; 19 | color: var(--color-base-60); 20 | opacity: var(--icon-opacity); 21 | font-size: var(--font-smallest); 22 | } 23 | 24 | .cb-tree-item-button { 25 | box-shadow: none !important; /* Obsidian Button class overrides */ 26 | background-color: transparent !important; /* Obsidian Button class overrides */ 27 | padding: 0 !important; /* Obsidian Button class overrides */ 28 | margin: 0 .2rem !important; /* Obsidian Button class overrides */ 29 | height: auto !important; /* Obsidian Button class overrides */ 30 | 31 | align-self: center; 32 | color: var(--icon-color); 33 | opacity: var(--icon-opacity); 34 | } 35 | 36 | .cb-tree-item-button > svg { 37 | width: 12px !important; /* Obsidian Button class overrides */ 38 | height: 12px !important; /* Obsidian Button class overrides */ 39 | stroke-width: 2.5px !important; /* Obsidian Button class overrides */ 40 | } 41 | .cb-tree-item-button:disabled { 42 | opacity: calc(var(--icon-opacity) * 0.5); 43 | } 44 | 45 | .cb-tree-item-button:not(:disabled):hover { 46 | opacity: var(--icon-opacity-active); 47 | color: var(--icon-color-focused); 48 | } 49 | 50 | .cb-view-empty { 51 | color: var(--text-muted); 52 | display: table; 53 | margin: 1rem auto; 54 | font-style: italic; 55 | } 56 | 57 | .cb-view-controls { 58 | display: flex; 59 | justify-content: center; 60 | align-items: center; 61 | margin-bottom: 0.5rem; 62 | } 63 | 64 | .cb-view-tree { 65 | padding-bottom: 1rem; /* To make sure all tree items are viewable, because of the statusbar */ 66 | } -------------------------------------------------------------------------------- /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 | "isolatedModules": true, 13 | "strictNullChecks": true, 14 | "lib": [ 15 | "DOM", 16 | "ES5", 17 | "ES6", 18 | "ES7" 19 | ] 20 | }, 21 | "include": [ 22 | "**/*.ts" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /versions.json: -------------------------------------------------------------------------------- 1 | { 2 | "1.0.0": "0.15.0", 3 | "1.1.0": "1.1.1", 4 | "1.1.1": "1.1.1", 5 | "1.2.0": "1.1.1", 6 | "1.2.1": "1.1.1", 7 | "1.3.0": "1.1.1", 8 | "1.4.0": "1.4.11" 9 | } --------------------------------------------------------------------------------