Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Enable preview feature to allow global filter to be at the end. #678

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
53d2d8e
Markdown lint fixes
sytone May 3, 2022
bea862f
Merge branch 'main' of https://github.com/schemar/obsidian-tasks
sytone May 4, 2022
f2104c9
feat: disregard the global tag
sytone May 4, 2022
1bb8f9f
feat: allow tag query to be hashless
sytone May 5, 2022
d8a3168
Merge branch 'main' of https://github.com/schemar/obsidian-tasks
sytone May 5, 2022
75eba71
test: refactor tag tests out and make them data driven
sytone May 5, 2022
d8a95b0
feat: update query language, add tests, make hash optional and query …
sytone May 5, 2022
547f776
test: add tests to validate substring
sytone May 5, 2022
9716007
test: chect to see if global tag is not found in query
sytone May 5, 2022
a3964f7
docs: update filter documentation on the tag query
sytone May 5, 2022
9c64527
feat: add ability to sort by tag instance/index
sytone May 7, 2022
f90abc4
Merge branch 'main' of https://github.com/schemar/obsidian-tasks
sytone May 7, 2022
4b88b4a
fix: resolved issues raised in PR.
sytone May 15, 2022
f02f2d2
build: add markdown lint to list command
sytone May 15, 2022
67e97c6
fix: resolve remaining comments and revert markdown lint changes
sytone May 15, 2022
b2ace95
docs: update grammar based issue and sorting description for tags
sytone May 15, 2022
3848523
Merge branch 'main' of https://github.com/schemar/obsidian-tasks
sytone May 17, 2022
788e25e
feat: Allow additional tasks states and filtering by states
sytone May 19, 2022
de6cb0f
feat: add cancelled and in progress along with minimal supported task…
sytone May 20, 2022
010f439
feat: add query capabilities for status
sytone May 20, 2022
bd31de1
build: enable minify main.js 604.9kb -> 283.8kb
sytone May 20, 2022
b08bdc8
build: move script to symlinks
sytone May 20, 2022
f58186a
fix: Update li rendering to match obsidian
sytone May 20, 2022
9d27b5d
feat: add feature flags to plugin
sytone May 21, 2022
149eb34
update flags for next menu feature only
sytone May 21, 2022
d5976ba
feat: add git attributes to force LF on windows
sytone May 22, 2022
292f684
Merge commit 'ff1216477242401139fee2031b28ebec9422334c' into sytone/i…
sytone May 22, 2022
f94572d
There should be an option to put the global filter at the end
sytone May 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js text eol=lf
*.ts text eol=lf
101 changes: 52 additions & 49 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import esbuild from "esbuild";
import process from "process";
import builtins from 'builtin-modules'
import esbuildSvelte from "esbuild-svelte";
import sveltePreprocess from "svelte-preprocess";

const banner =
`/*
import process from 'process';
import esbuild from 'esbuild';
import builtins from 'builtin-modules';
import esbuildSvelte from 'esbuild-svelte';
import sveltePreprocess from 'svelte-preprocess';

const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source visit the plugins github repository
*/
Expand Down Expand Up @@ -130,44 +129,48 @@ THE SOFTWARE.
*/
`;

const prod = (process.argv[2] === 'production');

esbuild.build({
banner: {
js: banner,
},
bundle: true,
entryPoints: ['main.ts'],
external: [
'obsidian',
'electron',
'codemirror',
'@codemirror/autocomplete',
'@codemirror/closebrackets',
'@codemirror/commands',
'@codemirror/fold',
'@codemirror/gutter',
'@codemirror/history',
'@codemirror/language',
'@codemirror/rangeset',
'@codemirror/rectangular-selection',
'@codemirror/search',
'@codemirror/state',
'@codemirror/stream-parser',
'@codemirror/text',
'@codemirror/view',
...builtins
],
format: 'cjs',
logLevel: "info",
outfile: 'main.js',
plugins: [
esbuildSvelte({
preprocess: sveltePreprocess()
}),
],
sourcemap: prod ? false : 'inline',
target: 'es2016',
treeShaking: true,
watch: !prod,
}).catch(() => process.exit(1));
const prod = process.argv[2] === 'production';
const dev = process.argv[2] === 'development';

esbuild
.build({
banner: {
js: banner,
},
bundle: true,
entryPoints: ['main.ts'],
external: [
'obsidian',
'electron',
'codemirror',
'@codemirror/autocomplete',
'@codemirror/closebrackets',
'@codemirror/commands',
'@codemirror/fold',
'@codemirror/gutter',
'@codemirror/history',
'@codemirror/language',
'@codemirror/rangeset',
'@codemirror/rectangular-selection',
'@codemirror/search',
'@codemirror/state',
'@codemirror/stream-parser',
'@codemirror/text',
'@codemirror/view',
...builtins,
],
format: 'cjs',
logLevel: 'info',
minify: prod ? true : false,
outfile: 'main.js',
plugins: [
esbuildSvelte({
preprocess: sveltePreprocess(),
}),
],
sourcemap: prod ? false : 'inline',
target: 'es2016',
treeShaking: true,
watch: !prod && !dev,
})
.catch(() => process.exit(1));
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "node esbuild.config.mjs production",
"build:dev": "node esbuild.config.mjs development",
"lint": "eslint ./src --fix && eslint ./tests --fix && tsc --noEmit --pretty && svelte-check",
"test": "jest --ci",
"test:dev": "jest --watch"
"test:dev": "jest --watch",
"test:obsidian": "pwsh -ExecutionPolicy Unrestricted -NoProfile -File ./scripts/Test-TasksInLocalObsidian.ps1"
},
"keywords": [
"obsidian",
Expand Down
53 changes: 53 additions & 0 deletions scripts/Test-TasksInLocalObsidian.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[CmdletBinding()]
param (
[Parameter(HelpMessage = 'The path to the plugins folder uner the .obsidian directory.')]
[String]
$ObsidianPluginRoot = $env:OBSIDIAN_PLUGIN_ROOT,
[Parameter(HelpMessage = 'The folder name of the plugin to copy the files to.')]
[String]
$PluginFolderName = 'obsidian-tasks-plugin'
)

$repoRoot = (Resolve-Path -Path $(git rev-parse --show-toplevel)).Path

if (-not (Test-Path $ObsidianPluginRoot)) {
Write-Error "Obsidian plugin root not found: $ObsidianPluginRoot"
return
} else {
Write-Host "Obsidian plugin root found: $ObsidianPluginRoot"
}

Push-Location $repoRoot
Write-Host "Repo root: $repoRoot"

yarn run build:dev

if ($?) {
Write-Output 'Build successful'

$filesToLink = @('main.js', 'styles.css', 'manifest.json')

foreach ($file in $filesToLink ) {
if ((Get-Item "$ObsidianPluginRoot/$PluginFolderName/$file" ).LinkType -ne 'SymbolicLink') {
Write-Output "Removing $file from plugin folder and linking"
Remove-Item "$ObsidianPluginRoot/$PluginFolderName/$file" -Force
New-Item -ItemType SymbolicLink -Path "$ObsidianPluginRoot/$PluginFolderName/$file" -Target "$repoRoot/$file"
} else {
(Get-Item "$ObsidianPluginRoot/$PluginFolderName/$file" ).LinkType
}
}

$hasHotReload = Test-Path "$ObsidianPluginRoot/$PluginFolderName/.hotreload"

if (!$hasHotReload) {
Write-Output 'Creating hotreload file'
'' | Set-Content "$ObsidianPluginRoot/$PluginFolderName/.hotreload"
}

yarn run dev

} else {
Write-Error 'Build failed'
}

Pop-Location
10 changes: 5 additions & 5 deletions src/Commands/CreateOrEdit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { App, Editor, MarkdownView, View } from 'obsidian';
import { StatusRegistry } from 'StatusRegistry';
import { TaskModal } from '../TaskModal';
import { Priority, Status, Task } from '../Task';
import { Status } from '../Status';
import { Priority, Task } from '../Task';

export const createOrEdit = (
checking: boolean,
Expand Down Expand Up @@ -64,11 +66,10 @@ const taskFromLine = ({ line, path }: { line: string; path: string }): Task => {
// Should never happen; everything in the regex is optional.
console.error('Tasks: Cannot create task on line:', line);
return new Task({
status: Status.Todo,
status: Status.TODO,
description: '',
path,
indentation: '',
originalStatusCharacter: ' ',
priority: Priority.None,
startDate: null,
scheduledDate: null,
Expand All @@ -86,7 +87,7 @@ const taskFromLine = ({ line, path }: { line: string; path: string }): Task => {

const indentation: string = nonTaskMatch[1];
const statusString: string = nonTaskMatch[3] ?? ' ';
const status = statusString === ' ' ? Status.Todo : Status.Done;
const status = StatusRegistry.getInstance().byIndicator(statusString);
let description: string = nonTaskMatch[4];

const blockLinkMatch = line.match(Task.blockLinkRegex);
Expand All @@ -101,7 +102,6 @@ const taskFromLine = ({ line, path }: { line: string; path: string }): Task => {
description,
path,
indentation,
originalStatusCharacter: statusString,
blockLink,
priority: Priority.None,
startDate: null,
Expand Down
120 changes: 120 additions & 0 deletions src/Commands/SelectStatus.ts.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// import { Editor, MarkdownView, View } from 'obsidian';

// import { Task } from '../Task';

// import { promptForMark } from '../ui/TaskMarkModal';
// export const selectStatus = (checking: boolean, editor: Editor, view: View) => {
// const mark = await promptForMark(this.app, this.plugin);
// if (mark) {
// this.markTaskOnLines(mark, this.getCurrentLinesFromEditor(editor));
// }

// if (checking) {
// if (!(view instanceof MarkdownView)) {
// // If we are not in a markdown view, the command shouldn't be shown.
// return false;
// }

// // The command should always trigger in a markdown view:
// // - Convert lines to list items.
// // - Convert list items to tasks.
// // - Toggle tasks' status.
// return true;
// }

// if (!(view instanceof MarkdownView)) {
// // Should never happen due to check above.
// return;
// }

// // We are certain we are in the editor due to the check above.
// const path = view.file?.path;
// if (path === undefined) {
// return;
// }

// const cursorPosition = editor.getCursor();
// const lineNumber = cursorPosition.line;
// const line = editor.getLine(lineNumber);

// const toggledLine = toggleLine({ line, path });
// editor.setLine(lineNumber, toggledLine);

// // The cursor is moved to the end of the line by default.
// // If there is text on the line, put the cursor back where it was on the line.
// if (/[^ [\]*-]/.test(toggledLine)) {
// editor.setCursor({
// line: cursorPosition.line,
// // Need to move the cursor by the distance we added to the beginning.
// ch: cursorPosition.ch + toggledLine.length - line.length,
// });
// }
// };

// const toggleLine = ({ line, path }: { line: string; path: string }): string => {
// let toggledLine: string = line;

// const task = Task.fromLine({
// line,
// path,
// sectionStart: 0, // We don't need this to toggle it here in the editor.
// sectionIndex: 0, // We don't need this to toggle it here in the editor.
// precedingHeader: null, // We don't need this to toggle it here in the editor.
// });
// if (task !== null) {
// toggledLine = toggleTask({ task });
// } else {
// // If the task is null this means that we have one of:
// // 1. a regular checklist item
// // 2. a list item
// // 3. a simple text line

// // The task regex will match checklist items.
// const regexMatch = line.match(Task.taskRegex);
// if (regexMatch !== null) {
// toggledLine = toggleChecklistItem({ regexMatch });
// } else {
// // This is not a checklist item. It is one of:
// // 1. a list item
// // 2. a simple text line

// const listItemRegex = /^([\s\t]*)([-*])/;
// if (listItemRegex.test(line)) {
// // Let's convert the list item to a checklist item.
// toggledLine = line.replace(listItemRegex, '$1$2 [ ]');
// } else {
// // Let's convert the line to a list item.
// toggledLine = line.replace(/^([\s\t]*)/, '$1- ');
// }
// }
// }

// return toggledLine;
// };

// const toggleTask = ({ task }: { task: Task }): string => {
// // Toggle a regular task.
// const toggledTasks = task.toggle();
// const serialized = toggledTasks
// .map((task: Task) => task.toFileLineString())
// .join('\n');

// return serialized;
// };

// const toggleChecklistItem = ({
// regexMatch,
// }: {
// regexMatch: RegExpMatchArray;
// }): string => {
// // It's a checklist item, let's toggle it.
// const indentation = regexMatch[1];
// const statusString = regexMatch[2].toLowerCase();
// const body = regexMatch[3];

// const toggledStatusString = statusString === ' ' ? 'x' : ' ';

// const toggledLine = `${indentation}- [${toggledStatusString}] ${body}`;

// return toggledLine;
// };
9 changes: 9 additions & 0 deletions src/Commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { App, Editor, Plugin, View } from 'obsidian';

import { createOrEdit } from './CreateOrEdit';
//import { selectStatus } from './SelectStatus';

import { toggleDone } from './ToggleDone';

Expand Down Expand Up @@ -32,5 +34,12 @@ export class Commands {
icon: 'check-in-circle',
editorCheckCallback: toggleDone,
});

// plugin.addCommand({
// id: 'select-status-modal',
// name: 'Select Status',
// icon: 'check-in-circle',
// editorCheckCallback: selectStatus,
// });
}
}
4 changes: 2 additions & 2 deletions src/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ interface CacheUpdateData {
export class Events {
private obsidianEvents: ObsidianEvents;

constructor({ obsidianEents }: { obsidianEents: ObsidianEvents }) {
this.obsidianEvents = obsidianEents;
constructor({ obsidianEvents }: { obsidianEvents: ObsidianEvents }) {
this.obsidianEvents = obsidianEvents;
}

public onCacheUpdate(
Expand Down
Loading