How do you map changes between a CodeMirror component and an array of objects?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- react, typescript
- Lĩnh vực
- developer-experience, documentation
Hướng nghiên cứu
Bắt đầu với ví dụ InputWithFields và logic handleTextChange của nó trong issue; không có tệp nào trong repository hoặc test nào được xác định. Xác định vị trí phù hợp cho một ví dụ tích hợp CodeMirror/RangeSet, sau đó ghi lại cách xử lý trường hợp sử dụng mảng các đối tượng này và những gì các cập nhật thành công sẽ tạo ra.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I have an array of objects that are represented in a CodeMirror component. I'm trying to work out how to map changes in the CodeMirror to the object. I'm using a RangeSet to hold the underlying object. I was expecting I could use RangeSet.map() to apply the changes from the CodeMirror onto the object RangeSet. I'm not seeing that happen.
Is there an example that can help me understand how to handle this use case in a good way?
type Text = { type: "text"; textValue: string };
type Field = {
type: "field";
textValue: string;
field: {
fieldId: string;
};
};
export type TextWithField = (Text | Field)[];
class TextOrFieldRange extends RangeValue {
type: "text" | "field";
textOrField: Text | Field;
theRange;
constructor(
from: number,
to: number,
type: "text" | "field",
textOrField: Text | Field
) {
super();
this.type = type;
this.textOrField = { ...textOrField };
this.theRange = this.range(from, to);
}
eq(other: RangeValue): boolean {
return (
other instanceof TextOrFieldRange &&
this.type === other.type &&
this.theRange.from === other.theRange.from &&
this.theRange.to === other.theRange.to
);
}
}
const InputWithFields = ({
textWithFields,
setTextWithFields,
}: {
textWithFields: TextWithField;
setTextWithFields: (textWithFields: TextWithField) => void;
}) => {
const rangeBuilder = new RangeSetBuilder<TextOrFieldRange>();
let combinedText = "";
const fieldRanges: [number, number][] = [];
textWithFields.forEach((item) => {
const start = combinedText.length;
combinedText += item.textValue;
const end = combinedText.length;
rangeBuilder.add(
start,
end,
new TextOrFieldRange(start, combinedText.length, item.type, item)
);
item.type == "field" && fieldRanges.push([start, end]);
});
const combinedRanges = rangeBuilder.finish();
const handleTextChange = (value: string, viewUpdate: ViewUpdate) => {
const newRanges = combinedRanges.map(viewUpdate.changes.desc);
const iterator = newRanges.iter();
const newTextWithFields: TextWithField = [];
while (iterator.value !== null) {
newTextWithFields.push(iterator.value.textOrField);
iterator.next();
}
setTextWithFields(newTextWithFields);
};
const highlightRanges = rangeHighlighter(fieldRanges);
return (
<CodeMirror
value={combinedText}
onChange={handleTextChange}
theme="none"
basicSetup={false}
editable={true}
extensions={[...extensions, highlightRanges]}
maxWidth="100%"
height="100px"
/>
);
};
- Ngôn ngữ chính
- TypeScript
- Star
- 2.3k
- Fork
- 162
- Merge trung bình
- 2 giờ 41 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của uiwjs/react-codemirror
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
uiwjs/react-codemirror#766 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
uiwjs/react-codemirror#765 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
uiwjs/react-codemirror#772 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
uiwjs/react-codemirror#770 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
uiwjs/react-codemirror#767 · 2 bình luận ·
Tất cả issue của uiwjs/react-codemirror
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
anomalyco/opencode#56380 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
BUG | `MCP 服务器` | 全局层行的停用/启用与删除报 404 server row not found,编辑保存会在 profile 层复制出重复行Có thể đã có người làm @w6242652 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Chocobozzz/PeerTube#7832 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Pay to use?Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 66/100
darkreader/darkreader#16108 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày