Skip to content

Commit 2545fc2

Browse files
committed
temp(key handling with lists)
1 parent 03987d6 commit 2545fc2

File tree

6 files changed

+576
-77
lines changed

6 files changed

+576
-77
lines changed

src/components/text-editor/list-functionality-development-log.md

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,80 @@ The implementation will proceed in the following phases:
8181
- [x] No regression in current list functionality has been introduced
8282
- [x] Implementation follows the core principles established in implementation plan
8383

84-
### [Date 2]
85-
*To be filled in as work progresses*
84+
### [March 26, 2024]
85+
86+
**Fixed List Command Handling and Tests**
87+
88+
- Improved tests for the `list-key-handler.ts` plugin
89+
- Fixed test setup to properly use mock DOM environment
90+
- Enhanced test cases for Tab and Shift+Tab operations
91+
- Improved verification of list structure changes
92+
93+
**Fixed List Command Toggle Behavior**
94+
95+
- Fixed a critical bug in `handleListWithSelection` function in `menu-commands.ts`
96+
- Corrected the handling of toggling between different list types (bullet/ordered)
97+
- Fixed the issue with toggling list off back to paragraphs
98+
- Removed unnecessary attempt to sink list items before checking list type
99+
100+
**Implementation Details**
101+
- Modified the handling in `handleListWithSelection` to:
102+
1. First check if we're already in the target list type, and if so, toggle it off
103+
2. Next check if we're in a different list type, and if so, convert between types
104+
3. Finally, wrap content in a list if not already in a list
105+
106+
**Verification Checklist**
107+
- [x] All existing tests now pass after changes
108+
- [x] No regression in current list functionality has been introduced
109+
- [x] All tests for list key handling now pass successfully
110+
- [x] Tests correctly verify list indentation and outdentation behavior
111+
112+
**Next Steps**
113+
- Implement Enter key handling for proper list item splitting
114+
- Implement Backspace key handling for joining list items
115+
- Add comprehensive tests for keyboard interaction in real usage scenarios
116+
117+
### [March 27, 2024]
118+
119+
**Implemented Enhanced Enter Key Behavior for Lists**
120+
121+
- Enhanced the list key handler plugin with improved Enter key behavior:
122+
- Splitting list items when Enter is pressed within content
123+
- Exiting a list when Enter is pressed in an empty list item
124+
- Added comprehensive tests for Enter key functionality:
125+
- Tests for splitting list items at various positions
126+
- Tests for exiting lists when in an empty list item
127+
- Added the `isEmptyListItem` utility function for detecting empty list items
128+
129+
**Implemented Backspace Key Behavior for Lists**
130+
131+
- Added Backspace key handling to the list key handler plugin:
132+
- Joining with previous list item when Backspace is pressed at start of list item
133+
- Lifting list item out of the list when Backspace is pressed at start of first item
134+
- Preserving regular Backspace behavior elsewhere
135+
- Added new utility function `isAtStartOfListItem` to detect when cursor is at list item start
136+
- Added comprehensive tests for Backspace key functionality:
137+
- Tests for joining with previous list items
138+
- Tests for lifting list items out of lists
139+
- Tests for default behavior when not at start of list item
140+
141+
**Implementation Details**
142+
- Used ProseMirror's built-in commands for optimal functionality:
143+
- `splitListItem` for Enter key handling
144+
- `joinBackward` and `liftListItem` for Backspace key handling through `chainCommands`
145+
- Ensured special key combinations (like Shift+Enter) are preserved
146+
- Added robust testing for edge cases and normal usage patterns
147+
148+
**Verification Checklist**
149+
- [x] All existing tests continue to pass after changes
150+
- [x] No regression in current list functionality has been introduced
151+
- [x] Each key handler properly prevents default browser behavior only when needed
152+
- [x] All utility functions are properly tested with both positive and negative cases
153+
154+
**Next Steps**
155+
- Update the prosemirror-adapter to properly register the enhanced list key handler
156+
- Add Markdown-style list creation with input rules (Phase 2)
157+
- Implement automatic list continuation when pressing Enter at end of list items (Phase 2)
86158

87159
### [Date 3]
88160
*To be filled in as work progresses*

src/components/text-editor/list-functionality-implementation-plan.md

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,30 @@ In implementing new list features, we must adhere to the following principles:
2424
- After each change, ensure regression tests pass before proceeding
2525
- Document any unexpected behaviors or edge cases discovered
2626

27+
## Implementation Plan
28+
29+
The implementation will proceed in the following phases:
30+
31+
### Phase 1: Key Navigation and Manipulation
32+
33+
- [x] Implement Tab/Shift+Tab for indenting/outdenting list items
34+
- [x] Enhance Enter behavior within lists for proper splitting
35+
- [x] Improve Backspace behavior at the start of list items for joining
36+
- [x] Add keyboard shortcuts for bullet and ordered lists
37+
38+
### Phase 2: Automatic List Creation
39+
40+
- [ ] Implement Markdown-style list creation with input rules
41+
- [ ] Add continue list behavior when pressing Enter at the end of a list item
42+
- [ ] Support for converting existing text to lists with shortcuts
43+
44+
### Phase 3: List Attributes and Advanced Features
45+
46+
- [ ] Add support for list item numbering options
47+
- [ ] Implement custom list markers
48+
- [ ] Enhance nested list styling and behavior
49+
- [ ] Add ARIA attributes for accessibility
50+
2751
## Phase 1: Key Navigation and Manipulation
2852

2953
### 1. Tab/Shift+Tab for Indenting/Outdenting List Items
@@ -146,51 +170,4 @@ In implementing new list features, we must adhere to the following principles:
146170
- Update the keymap in `MenuCommandFactory.buildKeymap()`
147171

148172
2. **Implementation Details:**
149-
```typescript
150-
// In MenuCommandFactory.buildKeymap()
151-
buildKeymap() {
152-
return {
153-
// Existing shortcuts...
154-
'Mod-B': this.getCommand(EditorMenuTypes.Bold),
155-
'Mod-I': this.getCommand(EditorMenuTypes.Italic),
156-
157-
// New list shortcuts
158-
'Mod-Shift-8': this.getCommand(EditorMenuTypes.BulletList),
159-
'Mod-Shift-9': this.getCommand(EditorMenuTypes.OrderedList),
160-
161-
// Rest of existing shortcuts...
162-
};
163-
}
164173
```
165-
166-
3. **Integration:**
167-
- Ensure shortcuts work with existing command structure
168-
- Add appropriate tests for shortcut functionality
169-
170-
## Phase 1 Integration Plan
171-
172-
1. **New Files to Create:**
173-
- `src/components/text-editor/prosemirror-adapter/plugins/list-key-handler.ts` - Key handler plugin for list-specific keys
174-
- `src/components/text-editor/prosemirror-adapter/menu/menu-command-utils/list-item-utils.ts` - Utilities for list item operations
175-
176-
2. **Files to Modify:**
177-
- `src/components/text-editor/prosemirror-adapter/menu/menu-commands.ts` - Update keyboard shortcuts
178-
- `src/components/text-editor/prosemirror-adapter/prosemirror-adapter.ts` - Register the new key handler plugin
179-
180-
3. **Testing Strategy:**
181-
- Create comprehensive tests for each key operation
182-
- Test edge cases (empty lists, nested lists, etc.)
183-
- Ensure existing functionality isn't broken
184-
185-
4. **Expected Challenges:**
186-
- Handling cursor position after operations
187-
- Managing selection across list boundaries
188-
- Ensuring proper nesting of lists
189-
190-
## Next Steps After Phase 1
191-
192-
Once Phase 1 is complete, we'll proceed to:
193-
194-
1. Implement Markdown-style list creation (Phase 2)
195-
2. Add automatic list continuation (Phase 2)
196-
3. Enhance list attributes and styling (Phase 3)

src/components/text-editor/prosemirror-adapter/menu/menu-commands.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,15 @@ const handleListWithSelection = (
278278

279279
// If an ancestor of type list_item is found, attempt to sink that list_item.
280280
if (ancestorDepth !== null) {
281-
if (sinkListItem(listItemType)(state, dispatch)) {
282-
return true;
281+
// If we're already in this list type, toggle it off (remove the list)
282+
if (isInListOfType(state, type)) {
283+
return removeListNodes(state, type, schema, dispatch);
283284
}
284-
}
285-
286-
if (isInListOfType(state, type)) {
287-
return removeListNodes(state, type, schema, dispatch);
288-
}
289285

290-
if (otherType && isInListOfType(state, otherType)) {
291-
return convertAllListNodes(state, otherType, type, dispatch);
286+
// If we're in a different list type, convert from one to the other
287+
if (otherType && isInListOfType(state, otherType)) {
288+
return convertAllListNodes(state, otherType, type, dispatch);
289+
}
292290
}
293291

294292
const modifiedTr = state.tr.setSelection(new TextSelection($from, $to));

src/components/text-editor/prosemirror-adapter/menu/menu-list-commands.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable camelcase */
22
import { Schema } from 'prosemirror-model';
33
import { EditorState, TextSelection } from 'prosemirror-state';
4-
import { createListCommand } from '../menu-commands';
5-
import { EditorMenuTypes } from '../types';
4+
import { createListCommand } from './menu-commands';
5+
import { EditorMenuTypes } from './types';
66

77
describe('List Commands', () => {
88
let schema: Schema;

0 commit comments

Comments
 (0)