[prev in list] [next in list] [prev in thread] [next in thread]
List: jedit-users
Subject: Re: [ jEdit-users ] (SOLVED) max-width for soft word-wrap
From: "Suraj N. Kurapati" <skurapat () ucsc ! edu>
Date: 2006-12-13 22:31:45
Message-ID: 45807F51.4010308 () ucsc ! edu
[Download RAW message or body]
Slava Pestov wrote:
> On 13-Dec-06, at 4:38 PM, Suraj N. Kurapati wrote:
>
>> I agree with you guys about UI complication. So I'll withdraw my
>> feature request. However, I still want to implement this feature
>> (hard-coded, no UI configuration) in my local checkout of jEdit SVN.
>>
>> I narrowed down the source code of interest to the
>> setMaxLineLength() method in the
>> org/gjt/sp/jedit/textarea/TextArea.java file. I want to edit that
>> method to be like:
>>
>> private void setMaxLineLength(int maxLineLen)
>> {
>> if(softWrap && maxLineLen > width_of_jedit_window)
>> {
>> wrapToWidth = true;
>> wrapMargin = painter.getWidth() - charWidth * 3;
>> return;
>> }
>>
>> // existing stuff ...
>> }
>>
>> But, I do not know how to determine the width of the jEdit window.
>> Can one of the developers provide a hint?
>
> You want the width of the text area minus scroll bars and gutter; not
> the width of the window.
>
> It's right there:
>
> painter.getWidth()
Thank you very much. I was able implement the feature with your
suggestion. I have attached the patch to this message, in case
anybody wants to use this feature.
Cheers.
["jEdit_SVNr8226_soft-wrap_max-width.patch" (text/x-patch)]
Index: org/gjt/sp/jedit/textarea/TextArea.java
===================================================================
--- org/gjt/sp/jedit/textarea/TextArea.java (revision 8226)
+++ org/gjt/sp/jedit/textarea/TextArea.java (working copy)
@@ -5768,6 +5768,38 @@
{
this.maxLineLen = maxLineLen;
+ /**
+ Makes soft word-wrap mode behave like the CSS "max-width" property:
+
+ 1. When the window width is less than the maximum, the wrapping behaves like \
wrap-margin is 0 (fits to the window). +
+ 2. When the window width is greater than the maximum, the wrapping behaves like \
fixed wrap-margin (wrapping restricted to the maximum width). +
+ @see discussion of this feature at: \
http://sourceforge.net/mailarchive/forum.php?thread_id=31224167&forum_id=5663 + */
+ if(softWrap)
+ {
+ // determine width of maximum rendered line
+ char[] foo = new char[maxLineLen];
+ for(int i = 0; i < foo.length; i++)
+ {
+ foo[i] = ' ';
+ }
+
+ int maxReneredLineLen = (int)painter.getFont().getStringBounds(
+ foo,0,foo.length,
+ painter.getFontRenderContext())
+ .getWidth();
+
+
+ if(painter.getWidth() < maxReneredLineLen)
+ {
+ wrapToWidth = true;
+ wrapMargin = painter.getWidth() - charWidth * 3;
+ return;
+ }
+ }
+
if(maxLineLen <= 0)
{
if(softWrap)
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
--
-----------------------------------------------
jEdit Users' List
jEdit-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic