-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
19 lines (13 loc) · 695 Bytes
/
Copy pathmodels.py
File metadata and controls
19 lines (13 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Domain type for the editor-undo mini-project: a mutable text buffer."""
from __future__ import annotations
class Document:
"""The receiver: commands operate on this buffer, it knows no history."""
def __init__(self, text: str = "") -> None:
self.text = text
def insert(self, position: int, chunk: str) -> None:
self.text = self.text[:position] + chunk + self.text[position:]
def delete(self, position: int, length: int) -> str:
"""Remove and return ``length`` characters at ``position``."""
removed = self.text[position : position + length]
self.text = self.text[:position] + self.text[position + length :]
return removed