diff -ur mc-4.7.5.5.orig/src/editor/edit.c mc-4.7.5.5/src/editor/edit.c
old
|
new
|
|
1651 | 1651 | |
1652 | 1652 | /* --------------------------------------------------------------------------------------------- */ |
1653 | 1653 | |
1654 | | char * |
1655 | | edit_get_buf_ptr (WEdit * edit, long byte_index) |
1656 | | { |
1657 | | unsigned long p; |
1658 | | |
1659 | | if (byte_index >= (edit->curs1 + edit->curs2)) |
1660 | | byte_index--; |
1661 | | |
1662 | | if (byte_index < 0) |
1663 | | return NULL; |
1664 | | |
1665 | | if (byte_index >= edit->curs1) |
1666 | | { |
1667 | | p = edit->curs1 + edit->curs2 - 1; |
1668 | | return (char *) (edit->buffers2[p >> S_EDIT_BUF_SIZE] + |
1669 | | (EDIT_BUF_SIZE - (p & M_EDIT_BUF_SIZE) - 1)); |
1670 | | } |
1671 | | else |
1672 | | { |
1673 | | return (char *) (edit->buffers1[byte_index >> S_EDIT_BUF_SIZE] + (0 & M_EDIT_BUF_SIZE)); |
1674 | | } |
1675 | | } |
1676 | | |
1677 | | /* --------------------------------------------------------------------------------------------- */ |
1678 | | |
1679 | 1654 | int |
1680 | 1655 | edit_get_utf (WEdit * edit, long byte_index, int *char_width) |
1681 | 1656 | { |
… |
… |
|
1742 | 1717 | int |
1743 | 1718 | edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width) |
1744 | 1719 | { |
1745 | | gchar *str, *buf = NULL; |
1746 | | int res = -1; |
1747 | | gunichar ch; |
1748 | | gchar *next_ch = NULL; |
1749 | | int width = 0; |
1750 | | |
1751 | | if (byte_index > 0) |
1752 | | byte_index--; |
1753 | | |
1754 | | if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0) |
1755 | | { |
1756 | | *char_width = 0; |
1757 | | return 0; |
1758 | | } |
1759 | | |
1760 | | ch = edit_get_utf (edit, byte_index, &width); |
1761 | | |
1762 | | if (width == 1) |
1763 | | { |
1764 | | *char_width = width; |
1765 | | return ch; |
1766 | | } |
1767 | | |
1768 | | str = edit_get_byte_ptr (edit, byte_index); |
1769 | | buf = edit_get_buf_ptr (edit, byte_index); |
1770 | | if (str == NULL || buf == NULL) |
1771 | | { |
1772 | | *char_width = 0; |
1773 | | return 0; |
1774 | | } |
1775 | | /* get prev utf8 char */ |
1776 | | if (str != buf) |
1777 | | str = g_utf8_find_prev_char (buf, str); |
1778 | | |
1779 | | if (str == NULL) |
1780 | | { |
1781 | | *char_width = 0; |
1782 | | return 0; |
1783 | | } |
1784 | | else |
1785 | | res = g_utf8_get_char_validated (str, -1); |
1786 | | |
1787 | | if (res < 0) |
1788 | | { |
1789 | | ch = *str; |
1790 | | width = 0; |
1791 | | } |
1792 | | else |
1793 | | { |
1794 | | ch = res; |
1795 | | /* Calculate UTF-8 char width */ |
1796 | | next_ch = g_utf8_next_char (str); |
1797 | | if (next_ch) |
1798 | | { |
1799 | | width = next_ch - str; |
1800 | | } |
1801 | | else |
1802 | | { |
1803 | | ch = 0; |
1804 | | width = 0; |
1805 | | } |
1806 | | } |
1807 | | *char_width = width; |
1808 | | return ch; |
| 1720 | int i, res; |
| 1721 | gchar tmpbuf[18 + 1], *str; |
| 1722 | |
| 1723 | if (byte_index > (edit->curs1 + edit->curs2) || byte_index <= 0) |
| 1724 | { |
| 1725 | *char_width = 0; |
| 1726 | return 0; |
| 1727 | } |
| 1728 | |
| 1729 | for (i = 0; i < 18; i++) |
| 1730 | tmpbuf[i] = edit_get_byte (edit, byte_index + i - 12); |
| 1731 | tmpbuf[18] = '\0'; |
| 1732 | |
| 1733 | str = g_utf8_find_prev_char (tmpbuf, tmpbuf + 12); |
| 1734 | if (str == NULL || g_utf8_next_char(str) != tmpbuf + 12) |
| 1735 | { |
| 1736 | *char_width = 1; |
| 1737 | return tmpbuf[11]; |
| 1738 | } |
| 1739 | else |
| 1740 | res = g_utf8_get_char_validated (str, -1); |
| 1741 | |
| 1742 | if (res < 0) |
| 1743 | { |
| 1744 | *char_width = 1; |
| 1745 | return tmpbuf[11]; |
| 1746 | } |
| 1747 | else |
| 1748 | { |
| 1749 | *char_width = tmpbuf + 12 - str; |
| 1750 | return res; |
| 1751 | } |
1809 | 1752 | } |
1810 | 1753 | |
1811 | 1754 | /* --------------------------------------------------------------------------------------------- */ |
diff -ur mc-4.7.5.5.orig/src/editor/edit-impl.h mc-4.7.5.5/src/editor/edit-impl.h
old
|
new
|
|
206 | 206 | int edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch); |
207 | 207 | int edit_get_byte (WEdit * edit, long byte_index); |
208 | 208 | char *edit_get_byte_ptr (WEdit * edit, long byte_index); |
209 | | char *edit_get_buf_ptr (WEdit * edit, long byte_index); |
210 | 209 | int edit_get_utf (WEdit * edit, long byte_index, int *char_width); |
211 | 210 | int edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width); |
212 | 211 | long edit_count_lines (WEdit * edit, long current, long upto); |