if (diff < 0)
{
- /* Adjust end poistions of properties starting before HEAD. */
+ /* Adjust end positions of properties starting before HEAD. */
for (i = 0; i < head->nprops; i++)
{
prop = head->stack[i];
}
-/* Delete volatile text properties between FROM and TO. If KEY is
- Mnil, we are going to delete text, thus both strongly and weakly
- volatile properties must be deleted. Otherwise we are going to
- modify a text property KEY, thus only strongly volatile properties
- whose key is not KEY must be deleted. */
+/* Delete volatile text properties between FROM and TO. If DELETING
+ is nonzero, we are going to delete text, thus both strongly and
+ weakly volatile properties must be deleted. Otherwise we are going
+ to modify a text property KEY, thus only strongly volatile
+ properties whose key is not KEY must be deleted. */
static void
-prepare_to_modify (MText *mt, int from, int to, MSymbol key)
+prepare_to_modify (MText *mt, int from, int to, MSymbol key, int deleting)
{
MTextPlist *plist = mt->plist, *prev = NULL;
int mask_bits = MTEXTPROP_VOLATILE_STRONG;
- int deleting = (key == Mnil) && (from < to);
- if (key == Mnil)
+ if (deleting)
mask_bits |= MTEXTPROP_VOLATILE_WEAK;
while (plist)
{
}
to = pos + len;
- prepare_to_modify (mt, pos, to, Mnil);
+ prepare_to_modify (mt, pos, to, Mnil, 1);
for (plist = mt->plist; plist; plist = plist->next)
{
MInterval *interval = pop_all_properties (plist, pos, to);
return;
}
if (pos > 0 && pos < mtext_nchars (mt))
- prepare_to_modify (mt, pos, pos, Mnil);
+ prepare_to_modify (mt, pos, pos, Mnil, 0);
for (pl_last = NULL, pl = mt->plist; pl; pl_last = pl, pl = pl->next)
{
}
}
+/* len1 > 0 && len2 > 0 */
+
void
-mtext__adjust_plist_for_change (MText *mt, int from, int to)
+mtext__adjust_plist_for_change (MText *mt, int pos, int len1, int len2)
{
- MTextPlist *plist;
+ int pos2 = pos + len1;
- prepare_to_modify (mt, from, to, Mnil);
- for (plist = mt->plist; plist; plist = plist->next)
+ prepare_to_modify (mt, pos, pos2, Mnil, 0);
+
+ if (len1 < len2)
{
- pop_all_properties (plist, from, to);
- xassert (check_plist (plist, 0) == 0);
+ int diff = len2 - len1;
+ MTextPlist *plist;
+
+ for (plist = mt->plist; plist; plist = plist->next)
+ {
+ MInterval *head = find_interval (plist, pos2);
+ MInterval *tail = mt->plist->tail;
+ MTextProperty *prop;
+ int i;
+
+ if (head->start == pos2)
+ head = head->prev;
+ while (tail != head)
+ {
+ for (i = 0; i < tail->nprops; i++)
+ {
+ prop = tail->stack[i];
+ if (prop->start == tail->start)
+ prop->start += diff, prop->end += diff;
+ }
+ tail->start += diff;
+ tail->end += diff;
+ tail = tail->prev;
+ }
+ for (i = 0; i < tail->nprops; i++)
+ tail->stack[i]->end += diff;
+ tail->end += diff;
+ }
+ }
+ else if (len1 > len2)
+ {
+ mtext__adjust_plist_for_delete (mt, pos + len2, len1 - len2);
}
}
M_CHECK_RANGE (mt, from, to, -1, 0);
- prepare_to_modify (mt, from, to, key);
+ prepare_to_modify (mt, from, to, key, 0);
plist = get_plist_create (mt, key, 1);
interval = pop_all_properties (plist, from, to);
prop = new_text_property (mt, from, to, key, val, 0);
M_CHECK_RANGE (mt, from, to, -1, 0);
- prepare_to_modify (mt, from, to, key);
+ prepare_to_modify (mt, from, to, key, 0);
plist = get_plist_create (mt, key, 1);
interval = pop_all_properties (plist, from, to);
if (num > 0)
M_CHECK_RANGE (mt, from, to, -1, 0);
- prepare_to_modify (mt, from, to, key);
+ prepare_to_modify (mt, from, to, key, 0);
plist = get_plist_create (mt, key, 1);
/* Find an interval that covers the position FROM. */
/* No property to pop. */
return 0;
- prepare_to_modify (mt, from, to, key);
+ prepare_to_modify (mt, from, to, key, 0);
/* If the found interval starts before FROM and has value(s), divide
it at FROM. */
M17N_OBJECT_REF (prop);
if (prop->mt)
mtext_detach_property (prop);
- prepare_to_modify (mt, from, to, prop->key);
+ prepare_to_modify (mt, from, to, prop->key, 0);
plist = get_plist_create (mt, prop->key, 1);
xassert (check_plist (plist, 0) == 0);
interval = pop_all_properties (plist, from, to);
if (! prop->mt)
return 0;
- prepare_to_modify (prop->mt, start, end, prop->key);
+ prepare_to_modify (prop->mt, start, end, prop->key, 0);
plist = get_plist_create (prop->mt, prop->key, 0);
xassert (plist);
detach_property (plist, prop, NULL);
M17N_OBJECT_REF (prop);
if (prop->mt)
mtext_detach_property (prop);
- prepare_to_modify (mt, from, to, prop->key);
+ prepare_to_modify (mt, from, to, prop->key, 0);
plist = get_plist_create (mt, prop->key, 1);
prop->mt = mt;
prop->start = from;