Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: createEmpty가 기본 A4 구역 1개 + 빈 문단을 포함해 즉시 편집 가능 (#1386)#1399

Open
oksure wants to merge 3 commits into
edwardkim:devel from
oksure:contrib/fix-1386-create-empty-section
Open

feat: createEmpty가 기본 A4 구역 1개 + 빈 문단을 포함해 즉시 편집 가능 (#1386) #1399
oksure wants to merge 3 commits into
edwardkim:devel from
oksure:contrib/fix-1386-create-empty-section

Conversation

@oksure

@oksure oksure commented Jun 12, 2026

Copy link
×ばつ84188 HU, 여백 좌우 30mm/위 20mm/아래 15mm, 머리말·꼬리말 15mm)로 `PageDef` 구성 — `renderer/page_layout.rs`의 `a4_page_def` 테스트 헬퍼와 동일 값 - `Paragraph::new_empty()` 문단 1개 포함, `set_document()`로 styles/composed/pagination 일괄 초기화 - `DocumentCore::new_empty()`는 변경하지 않음 — 내부 테스트 다수가 빈 코어에 직접 구역을 push하는 스캐폴딩으로 사용하므로, 공개 API 경계(`wasm_api::create_empty`)에서만 보강 ## 검증 - 신규 회귀 테스트 `test_create_empty_document_is_editable`: `getSectionCount()==1`, insertText, getTextRange, exportHwp, exportHwpx, export→재파싱 텍스트 보존 단언 - 기존 createEmpty 계약 유지 확인: `page_count()==1`, SVG/HTML 렌더, layer tree export 테스트 전부 통과 - `cargo fmt -- --check` / `cargo clippy --all-targets -- -D warnings` / `cargo test` 전체 통과 Closes #1386" data-view-component="true"> Copy Markdown
Contributor

문제 (#1386)

HwpDocument.createEmpty()가 구역 0개 문서를 생성해 getSectionCount() === 0이고, 모든 편집/조회 API가 "구역 인덱스 0 범위 초과"로 실패합니다. addSection류 API도 없어 사실상 사용 불가한 반쪽 API였습니다.

수정

이슈의 기대 1안: createEmpty가 기본 구역 1개(+빈 문단 1개)를 포함하도록 수정.

  • 한컴 새 문서 기본 용지(A4 세로 ×ばつ84188 HU, 여백 좌우 30mm/위 20mm/아래 15mm, 머리말·꼬리말 15mm)로 PageDef 구성 — renderer/page_layout.rsa4_page_def 테스트 헬퍼와 동일 값
  • Paragraph::new_empty() 문단 1개 포함, set_document()로 styles/composed/pagination 일괄 초기화
  • DocumentCore::new_empty()는 변경하지 않음 — 내부 테스트 다수가 빈 코어에 직접 구역을 push하는 스캐폴딩으로 사용하므로, 공개 API 경계(wasm_api::create_empty)에서만 보강

검증

  • 신규 회귀 테스트 test_create_empty_document_is_editable: getSectionCount()==1, insertText, getTextRange, exportHwp, exportHwpx, export→재파싱 텍스트 보존 단언
  • 기존 createEmpty 계약 유지 확인: page_count()==1, SVG/HTML 렌더, layer tree export 테스트 전부 통과
  • cargo fmt -- --check / cargo clippy --all-targets -- -D warnings / cargo test 전체 통과

Closes #1386

...1386)
구역 0개 문서는 모든 편집/조회 API가 "구역 인덱스 0 범위 초과"로
실패해 createEmpty가 사실상 사용 불가했다. 한컴 새 문서 기본 용지
(A4, 여백 좌우 30/위 20/아래 15mm)로 구역 1개 + 빈 문단 1개를 구성해
set_document로 초기화한다.
- 회귀 테스트: 구역 수/insertText/getTextRange/exportHwp/exportHwpx/
 재파싱 보존 단언 (test_create_empty_document_is_editable)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 12, 2026 13:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Ensures createEmpty returns an immediately usable document (at least 1 section + 1 paragraph) and adds a regression test to prevent "0 sections → all edit/read APIs fail" behavior (#1386).

Changes:

  • Add a wasm API regression test verifying edit/read/export/roundtrip after createEmpty.
  • Update HwpDocument::create_empty to construct a default A4 section and an empty paragraph instead of returning a 0-section document.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/wasm_api/tests.rs Adds regression test covering edit/read/export and reparse behavior for createEmpty.
src/wasm_api.rs Modifies create_empty to build a minimal editable document structure (A4 section + empty paragraph).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wasm_api.rs
Comment on lines 265 to 287
pub fn create_empty() -> HwpDocument {
let mut core = DocumentCore::new_empty();
core.paginate();
let mut section = Section::default();
// 한컴 새 문서 기본 용지: A4 세로, 여백 좌우 30mm / 위 20mm / 아래 15mm /
// 머리말·꼬리말 15mm (renderer/page_layout.rs의 a4_page_def와 동일 값)
section.section_def.page_def = crate::model::page::PageDef {
width: 59528,
height: 84188,
margin_left: 8504,
margin_right: 8504,
margin_top: 5669,
margin_bottom: 4252,
margin_header: 4252,
margin_footer: 4252,
margin_gutter: 0,
..Default::default()
};
section.paragraphs.push(Paragraph::new_empty());
let mut document = Document::default();
document.sections.push(section);
core.set_document(document);
HwpDocument { core }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paginate는 누락이 아니라 set_document 내부로 이동했습니다 — set_document()가 styles/composed 재구성 후 mark_all_sections_dirty() + self.paginate()까지 수행합니다 (document_core/commands/document.rs). 기존 계약을 고정하는 test_create_empty_document(page_count()==1)와 SVG/HTML 렌더 테스트들이 전부 통과합니다. 호출 흐름이 코드에서 안 보이는 점은 주석으로 명시해 두었습니다.

Comment thread src/wasm_api.rs Outdated
Comment on lines +268 to +281
// 한컴 새 문서 기본 용지: A4 세로, 여백 좌우 30mm / 위 20mm / 아래 15mm /
// 머리말·꼬리말 15mm (renderer/page_layout.rs의 a4_page_def와 동일 값)
section.section_def.page_def = crate::model::page::PageDef {
width: 59528,
height: 84188,
margin_left: 8504,
margin_right: 8504,
margin_top: 5669,
margin_bottom: 4252,
margin_header: 4252,
margin_footer: 4252,
margin_gutter: 0,
..Default::default()
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a88189f 에서 반영했습니다 — A4 기본 용지를 PageDef::a4_default() 모델 생성자로 이동해 단일 출처화했습니다. (renderer/page_layout.rs의 a4_page_def는 #[cfg(test)] 모듈 내부 헬퍼라 프로덕션에서 직접 재사용이 불가해 모델 쪽을 공용 출처로 삼았습니다.)

oksure and others added 2 commits June 12, 2026 13:51
createEmpty에 하드코딩했던 한컴 새 문서 기본 용지 값을 모델 생성자로
이동해 단일 출처화. set_document가 paginate까지 수행함을 주석으로 명시.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot Copilot left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /