Skip to content

MultiverseLearningProducts/Advanced-Text-Editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Unit 1: Advanced Text Editor with Linked Lists

Overview

This Skillable lab activity requires you to implement an advanced text editor that uses linked lists to manage text lines, cursor movement, and undo/redo functionality.

Learning Objectives

  • Implement a doubly linked list for text lines with bidirectional navigation
  • Create a circular linked list for undo/redo history management
  • Apply optimization techniques (size tracking, tail pointers)
  • Handle complex edge cases in linked list operations

Context

You're building an advanced text editor that needs to support:

  • Cursor movement (forward/backward through text lines)
  • Undo/redo functionality with circular history
  • Efficient text manipulation operations

The system requires:

  • A doubly linked list for text lines with bidirectional navigation
  • A circular linked list for undo/redo history management
  • Optimization for performance
  • Handling of complex edge cases

Project Structure

src/main/java/com/jse/texteditor/
├── TextLineNode.java      # Node class for doubly linked list
├── TextEditor.java         # Main editor class
├── HistoryNode.java        # Node class for circular history list
└── EditorState.java       # State class for undo/redo

src/test/java/com/jse/texteditor/
└── TextEditorTest.java    # Test cases

Requirements

1. TextLineNode Class

  • String text - The text content of the line
  • TextLineNode next - Reference to next node
  • TextLineNode previous - Reference to previous node
  • Constructor to initialize with text

2. TextEditor Class

  • Use doubly linked list to store text lines
  • Maintain head, tail, and current cursor position
  • Implement the following methods:
    • insertLine(String text) - Insert a new line at cursor position
    • deleteLine() - Delete line at cursor position
    • moveCursorForward() - Move cursor to next line
    • moveCursorBackward() - Move cursor to previous line
    • getCurrentLine() - Get text at cursor position
    • getLineCount() - Get total number of lines (O(1) using size tracking)
    • getAllLines() - Get all lines as a list

3. History Management (Circular Linked List)

  • Implement circular linked list for undo/redo history
  • Each HistoryNode stores an EditorState snapshot
  • Implement:
    • undo() - Restore previous editor state
    • redo() - Restore next editor state (if available)
    • saveState() - Save current state to history

4. Optimization Features

  • Size tracking for O(1) line count operations
  • Tail pointer maintenance for efficient append operations
  • Efficient cursor movement using bidirectional traversal

5. Edge Cases to Handle

  • Empty document (no lines)
  • Single line document
  • Cursor at boundaries (beginning/end)
  • History overflow (circular wrap)
  • Null references

Implementation Steps

  1. Design the data structures - Plan TextLineNode, HistoryNode, and TextEditor classes
  2. Implement doubly linked list - Create TextLineNode and basic TextEditor structure
  3. Implement cursor movement - Add bidirectional traversal methods
  4. Implement circular history - Create HistoryNode and circular list structure
  5. Implement undo/redo - Add state management and navigation
  6. Add optimizations - Implement size tracking and tail pointers
  7. Handle edge cases - Test and fix boundary conditions
  8. Test and debug - Run test cases and optimize performance

Testing

Run the provided test cases:

mvn test

Resources

  • Starter code framework provided
  • Test cases for validation
  • Performance benchmarks included

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages