fix: css issue with create task

This commit is contained in:
Quorafind 2025-07-18 14:54:31 +08:00
parent 9477d963a0
commit 8967916eb0
12 changed files with 64 additions and 11378 deletions

View file

@ -46,7 +46,7 @@ export class App {
},
trigger: function (eventName: string, ...args: any[]) {
if (this._events[eventName]) {
this._events[eventName].forEach(callback => callback(...args));
this._events[eventName].forEach((callback: any) => callback(...args));
}
},
getFileByPath: function (path: string) {

View file

@ -62,21 +62,21 @@ jest.mock("obsidian", () => ({
// Mock moment module
jest.mock("moment", () => {
const moment = function(input) {
const moment = function(input?: any) {
return {
format: () => "2024-01-01",
diff: () => 0,
startOf: () => moment(),
endOf: () => moment(),
startOf: () => moment(input),
endOf: () => moment(input),
isSame: () => true,
isSameOrBefore: () => true,
isSameOrAfter: () => true,
isBefore: () => false,
isAfter: () => false,
isBetween: () => true,
clone: () => moment(),
add: () => moment(),
subtract: () => moment(),
clone: () => moment(input),
add: () => moment(input),
subtract: () => moment(input),
valueOf: () => Date.now(),
toDate: () => new Date(),
weekday: () => 0,

View file

@ -20,21 +20,21 @@ jest.mock("obsidian", () => ({
// Mock moment module
jest.mock("moment", () => {
const moment = function(input) {
const moment = function(input?: any) {
return {
format: () => "2024-01-01",
diff: () => 0,
startOf: () => moment(),
endOf: () => moment(),
startOf: () => moment(input),
endOf: () => moment(input),
isSame: () => true,
isSameOrBefore: () => true,
isSameOrAfter: () => true,
isBefore: () => false,
isAfter: () => false,
isBetween: () => true,
clone: () => moment(),
add: () => moment(),
subtract: () => moment(),
clone: () => moment(input),
add: () => moment(input),
subtract: () => moment(input),
valueOf: () => Date.now(),
toDate: () => new Date(),
weekday: () => 0,
@ -99,6 +99,7 @@ describe("Backward Compatibility Tests", () => {
start: { line: 0, ch: 0 },
end: { line: 0, ch: 1 },
editor: {} as Editor,
file: {} as any,
};
const suggestions = suggest.getSuggestions(mockContext);
@ -117,6 +118,7 @@ describe("Backward Compatibility Tests", () => {
start: { line: 0, ch: 0 },
end: { line: 0, ch: 1 },
editor: {} as Editor,
file: {} as any,
};
const suggestions = suggest.getSuggestions(mockContext);
@ -284,6 +286,7 @@ describe("Backward Compatibility Tests", () => {
start: { line: 0, ch: 0 },
end: { line: 0, ch: 1 },
editor: {} as Editor,
file: {} as any,
};
const suggestions = suggest.getSuggestions(mockContext);

View file

@ -21,21 +21,21 @@ jest.mock("obsidian", () => ({
// Mock moment module
jest.mock("moment", () => {
const moment = function(input) {
const moment = function(input?: any) {
return {
format: () => "2024-01-01",
diff: () => 0,
startOf: () => moment(),
endOf: () => moment(),
startOf: () => moment(input),
endOf: () => moment(input),
isSame: () => true,
isSameOrBefore: () => true,
isSameOrAfter: () => true,
isBefore: () => false,
isAfter: () => false,
isBetween: () => true,
clone: () => moment(),
add: () => moment(),
subtract: () => moment(),
clone: () => moment(input),
add: () => moment(input),
subtract: () => moment(input),
valueOf: () => Date.now(),
toDate: () => new Date(),
weekday: () => 0,

View file

@ -22,21 +22,21 @@ jest.mock("obsidian", () => ({
// Mock moment module
jest.mock("moment", () => {
const moment = function(input) {
const moment = function(input?: any) {
return {
format: () => "2024-01-01",
diff: () => 0,
startOf: () => moment(),
endOf: () => moment(),
startOf: () => moment(input),
endOf: () => moment(input),
isSame: () => true,
isSameOrBefore: () => true,
isSameOrAfter: () => true,
isBefore: () => false,
isAfter: () => false,
isBetween: () => true,
clone: () => moment(),
add: () => moment(),
subtract: () => moment(),
clone: () => moment(input),
add: () => moment(input),
subtract: () => moment(input),
valueOf: () => Date.now(),
toDate: () => new Date(),
weekday: () => 0,

View file

@ -321,10 +321,11 @@ export class MinimalQuickCaptureModal extends Modal {
if (coords) {
this.showMenuAtCoords(menu, coords.left, coords.top);
} else if (this.dateButton) {
const rect = this.dateButton.getBoundingClientRect();
this.showMenuAtCoords(
menu,
this.dateButton.offsetLeft,
this.dateButton.offsetTop
rect.left,
rect.bottom + 5
);
}
}
@ -363,10 +364,11 @@ export class MinimalQuickCaptureModal extends Modal {
if (coords) {
this.showMenuAtCoords(menu, coords.left, coords.top);
} else if (this.priorityButton) {
const rect = this.priorityButton.getBoundingClientRect();
this.showMenuAtCoords(
menu,
this.priorityButton.offsetLeft,
this.priorityButton.offsetTop
rect.left,
rect.bottom + 5
);
}
}
@ -423,10 +425,11 @@ export class MinimalQuickCaptureModal extends Modal {
if (coords) {
this.showMenuAtCoords(menu, coords.left, coords.top);
} else if (this.locationButton) {
const rect = this.locationButton.getBoundingClientRect();
this.showMenuAtCoords(
menu,
this.locationButton.offsetLeft,
this.locationButton.offsetTop
rect.left,
rect.bottom + 5
);
}
}

View file

@ -1,196 +0,0 @@
# Universal Suggest System
This document describes the new Universal Suggest System that provides unified, high-priority suggest functionality for special characters in the Task Progress Bar plugin.
## Overview
The Universal Suggest System replaces the previous scattered suggest implementations with a unified architecture that:
- Provides dynamic priority management through workspace suggest array manipulation
- Supports special characters: `!` (priority), `~` (date), `*` (target), `#` (tags)
- Maintains backward compatibility with existing MinimalQuickCaptureSuggest
- Offers extensible architecture for custom suggest implementations
## Architecture
### Core Components
1. **UniversalEditorSuggest**: Base class extending EditorSuggest<T>
2. **SuggestManager**: Manages dynamic suggest registration and priority
3. **SpecialCharacterSuggests**: Provides specific suggestions for each trigger character
### Key Features
- **Dynamic Priority**: Suggests are inserted at the beginning of `app.workspace.editorSuggest.suggests` array
- **Context Filtering**: Supports context-specific suggest activation
- **Lifecycle Management**: Automatic cleanup when modals close
- **Extensible Options**: Easy to add new trigger characters and suggestions
## Usage
### Basic Setup
```typescript
import { SuggestManager, UniversalEditorSuggest } from "./components/suggest";
// Initialize in plugin onload
this.globalSuggestManager = new SuggestManager(this.app, this);
// In modal onOpen
this.suggestManager.startManaging();
const suggest = this.suggestManager.enableForMinimalModal(editor);
suggest.enable();
// In modal onClose
this.suggestManager.stopManaging();
```
### Custom Suggest Options
```typescript
// Add custom suggest option
const customOption = {
id: "custom-action",
label: "Custom Action",
icon: "star",
description: "Perform custom action",
replacement: "% ",
trigger: "%",
action: (editor, cursor) => {
// Custom action implementation
console.log("Custom action triggered");
}
};
suggest.addSuggestOption(customOption);
```
### Context Filtering
```typescript
// Add context-specific filter
manager.addContextFilter("my-context", (editor, file) => {
return file.path.includes("specific-folder");
});
// Create suggest with context
const suggest = manager.createUniversalSuggest("my-context");
```
## Special Characters
### Priority (`!`)
- `! 🔺` - Highest priority
- `! ⏫` - High priority
- `! 🔼` - Medium priority
- `! 🔽` - Low priority
- `! ⏬` - Lowest priority
### Date (`~`)
- `~ YYYY-MM-DD` - Today's date
- `~ YYYY-MM-DD` - Tomorrow's date
- `~ ` - Open date picker
- `~ ⏰ ` - Scheduled date format
### Target (`*`)
- `* Inbox` - Save to inbox
- `* Daily` - Save to daily note
- `* Current` - Save to current file
- `* ` - Open file picker
- `* filename` - Recent files
### Tags (`#`)
- `# important` - Important tag
- `# urgent` - Urgent tag
- `# work` - Work tag
- `# personal` - Personal tag
- `# ` - Open tag picker
- `# existing-tag` - Existing vault tags
## Migration Guide
### From MinimalQuickCaptureSuggest
The existing MinimalQuickCaptureSuggest continues to work with enhanced functionality:
```typescript
// Old usage (still works)
const suggest = new MinimalQuickCaptureSuggest(app, plugin);
suggest.setMinimalMode(true);
// New enhanced suggestions are automatically available
// @ is automatically mapped to * for target location
```
### From Custom Suggest Implementations
Replace custom EditorSuggest implementations:
```typescript
// Old
class CustomSuggest extends EditorSuggest<string> {
// Custom implementation
}
// New
const suggest = manager.createUniversalSuggest("custom", {
triggerChars: ["@"],
contextFilter: (editor, file) => /* custom logic */
});
```
## Performance Considerations
- Suggests are created and destroyed dynamically to minimize memory usage
- Context filters are evaluated efficiently
- Workspace suggest array manipulation is optimized for frequent operations
- Cleanup is automatic when modals close
## Testing
Run the test suite to verify functionality:
```bash
npm test -- UniversalSuggest.test.ts
npm test -- SuggestPerformance.test.ts
npm test -- SuggestBackwardCompatibility.test.ts
```
## Troubleshooting
### Common Issues
1. **Suggests not appearing**: Ensure `startManaging()` is called before creating suggests
2. **Priority not working**: Check that suggests are added with `addSuggestWithPriority()`
3. **Context filtering**: Verify context filters return boolean values
4. **Memory leaks**: Always call `stopManaging()` or `cleanup()` when done
### Debug Mode
Enable debug logging:
```typescript
const manager = new SuggestManager(app, plugin, {
enableDynamicPriority: true,
// Add debug logging
});
// Log current suggest order
manager.debugLogSuggestOrder();
```
## Future Enhancements
- Support for custom trigger character patterns
- Advanced context filtering with regex support
- Suggest caching for improved performance
- Integration with other plugin suggest systems
- Visual suggest priority indicators
## API Reference
See the TypeScript definitions in the source files for complete API documentation:
- `UniversalEditorSuggest.ts` - Core suggest implementation
- `SuggestManager.ts` - Suggest lifecycle management
- `SpecialCharacterSuggests.ts` - Built-in special character handlers

View file

@ -40,7 +40,7 @@ export class SuggestManager {
this.isManaging = true;
// Store original order for restoration
this.originalSuggestsOrder = [...this.app.workspace.editorSuggest.suggests];
this.originalSuggestsOrder = [...(this.app.workspace as any).editorSuggest.suggests];
}
/**
@ -54,7 +54,7 @@ export class SuggestManager {
// Restore original order if needed
if (this.originalSuggestsOrder.length > 0) {
this.app.workspace.editorSuggest.suggests = [...this.originalSuggestsOrder];
(this.app.workspace as any).editorSuggest.suggests = [...this.originalSuggestsOrder];
}
this.isManaging = false;
@ -77,7 +77,7 @@ export class SuggestManager {
this.activeSuggests.set(id, suggest);
// Insert at the beginning for high priority
this.app.workspace.editorSuggest.suggests.unshift(suggest);
(this.app.workspace as any).editorSuggest.suggests.unshift(suggest);
}
/**
@ -88,9 +88,9 @@ export class SuggestManager {
if (!suggest) return;
// Remove from workspace
const index = this.app.workspace.editorSuggest.suggests.indexOf(suggest);
const index = (this.app.workspace as any).editorSuggest.suggests.indexOf(suggest);
if (index !== -1) {
this.app.workspace.editorSuggest.suggests.splice(index, 1);
(this.app.workspace as any).editorSuggest.suggests.splice(index, 1);
}
// Remove from our tracking
@ -222,7 +222,7 @@ export class SuggestManager {
* Debug: Log current suggest order
*/
debugLogSuggestOrder(): void {
console.log("Current suggest order:", this.app.workspace.editorSuggest.suggests);
console.log("Current suggest order:", (this.app.workspace as any).editorSuggest.suggests);
console.log("Managed suggests:", Array.from(this.activeSuggests.keys()));
}

View file

@ -11,6 +11,7 @@ import {
import TaskProgressBarPlugin from "../../index";
import { t } from "../../translations/helper";
import { getSuggestOptionsByTrigger } from "./SpecialCharacterSuggests";
import "../../styles/universal-suggest.css";
export interface SuggestOption {
id: string;
@ -126,21 +127,17 @@ export class UniversalEditorSuggest extends EditorSuggest<SuggestOption> {
const container = el.createDiv({ cls: "universal-suggest-item" });
// Icon
const iconEl = container.createDiv({ cls: "universal-suggest-icon" });
setIcon(iconEl, suggestion.icon);
container.createDiv({ cls: "universal-suggest-container" },(el)=>{
const icon = el.createDiv({ cls: "universal-suggest-icon" });
setIcon(icon, suggestion.icon);
// Content
const contentEl = container.createDiv({
cls: "universal-suggest-content",
});
contentEl.createDiv({
cls: "universal-suggest-label",
text: suggestion.label,
});
contentEl.createDiv({
cls: "universal-suggest-description",
text: suggestion.description,
el.createDiv({
cls: "universal-suggest-label",
text: suggestion.label,
});
});
}
/**

View file

@ -3,7 +3,6 @@
.universal-suggest-item {
display: flex;
align-items: center;
padding: 8px 12px;
cursor: pointer;
border-radius: 4px;
transition: background-color 0.1s ease;
@ -17,6 +16,14 @@
background-color: var(--background-modifier-active-hover);
}
.universal-suggest-container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
overflow: hidden;
}
.universal-suggest-icon {
display: flex;
align-items: center;
@ -76,7 +83,7 @@
.universal-suggest-item {
border: 1px solid var(--background-modifier-border);
margin-bottom: 2px;
}
}
.universal-suggest-item:hover,
.universal-suggest-item.is-selected {

View file

@ -312,7 +312,7 @@ export class TaskGeniusIconManager extends Component {
inset-inline-start: -1px;
position: absolute;
width: calc(var(--checkbox-size) * 1.2);
height: calc(var(--checkbox-size) * 1.2)
height: calc(var(--checkbox-size) * 1.2);
display: block;
-webkit-mask-position: 52% 52%;
-webkit-mask-repeat: no-repeat;

11130
styles.css

File diff suppressed because one or more lines are too long