Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion extension/writing-process/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var RAW_DEBUG = false;
var WEBSOCKET_SERVER_URL = "wss://learning-observer.org/wsapi/in/";

import { googledocs_id_from_url } from './writing_common';

import { tab_id_from_url } from './writing_common';
import * as loEvent from 'lo_event/lo_event/lo_event.js';
import * as loEventDebug from 'lo_event/lo_event/debugLog.js';
import { websocketLogger } from 'lo_event/lo_event/websocketLogger.js';
Expand Down Expand Up @@ -210,6 +210,7 @@ chrome.webRequest.onBeforeRequest.addListener(
versus GMT. */
event = {
'doc_id': googledocs_id_from_url(request.url),
'tab_id': tab_id_from_url(request.url),
'url': request.url,
'bundles': JSON.parse(formdata.bundles),
'rev': formdata.rev,
Expand All @@ -223,6 +224,7 @@ chrome.webRequest.onBeforeRequest.addListener(
*/
event = {
'doc_id': googledocs_id_from_url(request.url),
'tab_id': tab_id_from_url(request.url),
'url': request.url,
'formdata': formdata,
'rev': formdata.rev,
Expand Down
15 changes: 15 additions & 0 deletions extension/writing-process/src/writing_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ export function googledocs_id_from_url(url) {
return null;
}

export function tab_id_from_url(url) {
/*
Given a URL like:
https://docs.google.com/document/d/<doc_id>/edit?tab=t.95yb7msfl8ul
extract the associated tab ID:
t.95yb7msfl8ul
Return null if not a valid URL or tab param.
*/
var match = url.match(/[?&]tab=([^&]+)/i);
if (match) {
return match[1];
}
return null;
}

var writing_lasthash = "";
function unique_id() {
/*
Expand Down
126 changes: 126 additions & 0 deletions googledoc_reconstruction/DOCUMENTATION_UPDATES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Documentation Updates - Multi-Tab System

## Overview
Updated documentation in response to reviewer feedback requesting more elaboration on how tabs work and what commands are associated with tabs. The information about how tabs operate is now thoroughly documented.

## Files Enhanced

### 1. **command_state.py** - Core Tab Management
- **TabState class**: Added comprehensive docstring explaining tab structure, metadata, and embedded elements
- **DocState class**: Added detailed explanation of:
- How tabs function in Google Docs (separate sections/pages)
- Complete command-to-tab mapping (which commands affect which aspects)
- Tab lifecycle and reconstruction workflow

- **apply_bundle() method**: Added explanation of bundle structure and how default_tab routing works

- **_apply_cmd() method**: Major enhancement with:
- Complete command routing explanation
- Full list of supported command types
- Documentation of how each command type affects tabs

#### Tab Metadata Commands (Now Documented)
- **MKCH** ("Make channel"): Initialize tab metadata with names
- Data structure: Deeply nested lists containing tab names
- When used: Document creation or tab addition
- Result: Sets human-readable tab names

- **UCP** ("Update caption"): Rename existing tabs
- Data structure: Tab ID + new name in nested format
- When used: User renames a tab
- Handles both specific tab ID and current tab context

- **AC** ("Add child"): Create new tabs
- Data structure: New tab ID + name data
- When used: User adds/duplicates a tab
- Initializes TabState and records creation timestamp

#### Text Editing Commands (Now Documented)
- **IS** ("Insert string"): Add text at position
- **DS** ("Delete substring"): Remove text in range
- **AS** ("Alter substring"): Replace text (delete + insert)
- All with 1-based indexing and placeholder awareness
- Detailed semantics and fallback behavior

#### Element Commands (Now Documented)
- **AE** ("Add element"): Register dropdowns, images, etc.
- Dropdown-definition: Holds available options
- Dropdown: Instance with selected value
- Other elements: Images (limited by log constraints)

- **TE** ("Tie element"): Embed element into text
- Special handling for dropdowns (deferred reconstruction)
- Placeholders for other elements (images, etc.)

#### Control Flow Commands
- **MLTI** ("Multi-command"): Wrapper containing sub-commands
- **NM** ("New mutation"): Routes commands to specific tabs via 'nmr' field

### 2. **ReconstructionState.py** - Document-Level Tab Management
- **ReconstructionState class**: Added detailed docstring explaining:
- Multi-document state management
- Key responsibilities (tracking documents, routing events, persistence)
- Complete workflow (loading, processing, saving)

- **reconstruct_from_events() function**: Enhanced with:
- Multi-tab reconstruction logic explanation
- Event sorting and ordering importance
- Tab routing mechanism
- Command processing pipeline
- Metadata tracking per document

### 3. **load_event.py** - Event and Tab Extraction
- **parse_tab_from_url() function**: Added comprehensive docstring:
- Multi-tab URL structure explanation
- Tab ID format and examples
- Default behavior when tab not found

- **GoogleDocsSaveEvent class**: Significantly expanded documentation:
- Multi-tab event structure
- Command bundle format
- Timing information usage
- Detailed attribute descriptions

### 4. **main_reconstruction.py** - Tab Rendering
- **build_full_text() function**: Enhanced with:
- Multi-tab rendering strategy explanation
- Tab ordering logic (by first_timestamp)
- Element reconstruction approach
- Output format with examples
- Section separation and formatting

## Key Concepts Now Documented

### Tab Identification
- Tab IDs start with 't.' (e.g., 't.0', 't.95y...', 't.4n9p3wa3df6o')
- 't.0' is the default/initial tab
- Extracted from Google Docs URLs via 'tab=' parameter

### Command Routing
- **URL routing**: Tab ID in URL's 'tab=' parameter
- **nm routing**: Tab ID in new mutation's 'nmr' field (Last 't.' string wins)
- **Explicit routing**: ucp and ac commands specify target tab
- **Default routing**: Text editing commands use current_tab parameter

### Reconstruction Workflow
1. Events sorted chronologically (server_time, timestamp)
2. Commands routed to appropriate TabState
3. Text modified, metadata tracked, elements registered
4. After all events: expand_dropdowns() converts metadata to readable text
5. Multi-tab sections rendered with headers and separators

### Element Handling
- **Dropdowns**: Reconstructed as readable "DROPDOWN: Config – Value"
- **Images**: Shown as placeholders (binary data not in logs)
- **Deferred processing**: Metadata gathered first, then reconstructed

## Benefits for System Integration

Developers can now understand:
1. **How tabs work**: Independent sections within a document with separate content
2. **Command mapping**: Which commands affect which tabs and tab properties
3. **Event flow**: How events route to tabs for processing
4. **Rendering**: How multi-tab content is presented in output
5. **State persistence**: How reconstruction state captures tab information

This documentation provides the "crucial information for determining the best way these will operate within the system" as requested by the reviewer.
Loading
Loading