From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#45837: 28.0.50; incorrect cursor position in visual-line-mode when word-wrap-by-category is t Date: Mon, 18 Jan 2021 19:14:10 +0200 Message-ID: <83a6t688wt.fsf@gnu.org> References: <838s8wdhbf.fsf@gnu.org> <83v9bzbp8s.fsf@gnu.org> <834kjiboqb.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5221"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 45837@debbugs.gnu.org To: liuhui1610@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 18 18:44:42 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1Ya2-0001GE-Bj for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Jan 2021 18:44:42 +0100 Original-Received: from localhost ([::1]:37772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1Ya1-00012Z-CE for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Jan 2021 12:44:41 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1Y7K-0001UC-JE for bug-gnu-emacs@gnu.org; Mon, 18 Jan 2021 12:15:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36695) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1Y7K-0001ms-8W for bug-gnu-emacs@gnu.org; Mon, 18 Jan 2021 12:15:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l1Y7K-0001Qg-37 for bug-gnu-emacs@gnu.org; Mon, 18 Jan 2021 12:15:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 18 Jan 2021 17:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45837 X-GNU-PR-Package: emacs Original-Received: via spool by 45837-submit@debbugs.gnu.org id=B45837.16109900545416 (code B ref 45837); Mon, 18 Jan 2021 17:15:02 +0000 Original-Received: (at 45837) by debbugs.gnu.org; 18 Jan 2021 17:14:14 +0000 Original-Received: from localhost ([127.0.0.1]:48239 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1Y6Y-0001PH-91 for submit@debbugs.gnu.org; Mon, 18 Jan 2021 12:14:14 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:56098) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1Y6W-0001P3-Id for 45837@debbugs.gnu.org; Mon, 18 Jan 2021 12:14:13 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:60098) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1Y6R-0001bU-Do; Mon, 18 Jan 2021 12:14:07 -0500 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:1254 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l1Y6N-0007Ny-WA; Mon, 18 Jan 2021 12:14:04 -0500 In-Reply-To: <834kjiboqb.fsf@gnu.org> (message from Eli Zaretskii on Fri, 15 Jan 2021 10:15:08 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:198092 Archived-At: > Date: Fri, 15 Jan 2021 10:15:08 +0200 > From: Eli Zaretskii > Cc: 45837@debbugs.gnu.org > > > From: Liu Hui > > Date: Fri, 15 Jan 2021 15:28:33 +0800 > > Cc: 45837@debbugs.gnu.org > > > > I have tested the patch and found that the condition `(= (cdr (nth 2 > > (posn-at-point))) orig-y)` was sometimes too strict. `posn-at-point` > > may give slightly different y positions for characters on the same > > line when different fonts were used (examples can be found in the > > HELLO file). If there are inline graphics (e.g. latex previews), the y > > position can also be different. > > Hmm... you are right. But that sounds like a bug in posn-at-point, I > will look into fixing it soon. Upon looking into this, it isn't a bug: posn-at-point is working as designed and documented: Return nil if POS is not visible in WINDOW. Otherwise, the return value is similar to that returned by ‘event-start’ for a mouse click at the upper left corner of the glyph corresponding to POS: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "At the upper left corner of the glyph". IOW, if we ask about a glyph from a small font on an otherwise tall visual line, posn-at-point will try to adjust the Y coordinate for the fact that the glyph is smaller, and thus its upper left corner is further down from the window top. So using the (X . Y) part of what posn-at-point returns is unworkable for the purpose of this issue: a character about which we are asking can be arbitrarily small, and thus to work in all the cases, we will have to allow for a very large tolerance, and that could miss some situations where we really end up on the next visual line. However, posn-at-point also returns the coordinates in (COLUMN . ROW) units, and we can use that instead. So I propose to fix the current code on master as below. WDYT? diff --git a/lisp/simple.el b/lisp/simple.el index 37c0885dcc..2c6e3916cd 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -7338,10 +7338,7 @@ kill-visual-line ;; of the kill before killing. (let ((opoint (point)) (kill-whole-line (and kill-whole-line (bolp))) - (orig-y (cdr (nth 2 (posn-at-point)))) - ;; FIXME: This tolerance should be zero! It isn't due to a - ;; bug in posn-at-point, see bug#45837. - (tol (/ (line-pixel-height) 2))) + (orig-vlnum (cdr (nth 6 (posn-at-point))))) (if arg (vertical-motion (prefix-numeric-value arg)) (end-of-visual-line 1) @@ -7352,8 +7349,8 @@ kill-visual-line ;; end-of-visual-line didn't overshoot due to complications ;; like display or overlay strings, intangible text, etc.: ;; otherwise, we don't want to kill a character that's - ;; unrelated to the place where the visual line wrapped. - (and (< (abs (- (cdr (nth 2 (posn-at-point))) orig-y)) tol) + ;; unrelated to the place where the visual line wraps. + (and (= (cdr (nth 6 (posn-at-point))) orig-vlnum) ;; Make sure we delete the character where the line wraps ;; under visual-line-mode, be it whitespace or a ;; character whose category set allows to wrap at it.