• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BathyScapheで画像のインラインプレビューを可能にするプラグイン


Commit MetaInfo

Revisãodbe280ee71116476492ccb72e8dc298a2b33e9d0 (tree)
Hora2014-01-29 21:28:04
Autormasakih <masakih@user...>
Commitermasakih

Mensagem de Log

[Mod] 画像の挿入位置を首都来るメソッドを分離

Mudança Sumário

Diff

--- a/BSInlinePreviewer.h
+++ b/BSInlinePreviewer.h
@@ -20,7 +20,7 @@
2020
2121 id threadView;
2222 NSTextStorage *textStrage;
23- unsigned actionIndex;
23+ NSUInteger actionIndex;
2424
2525 id previewAttributes;
2626
@@ -46,8 +46,8 @@
4646 - (id)targetThreadView;
4747 - (void)setTargetTextStorage:(NSTextStorage *)ts;
4848 - (NSTextStorage *)targetTextStorage;
49-- (void)setActionIndex:(unsigned)p;
50-- (unsigned)actionIndex;
49+- (void)setActionIndex:(NSUInteger)p;
50+- (NSUInteger)actionIndex;
5151 - (BOOL)prepareTarget;
5252
5353 - (id)previewAttributes;
--- a/BSInlinePreviewer.m
+++ b/BSInlinePreviewer.m
@@ -128,64 +128,22 @@ static NSString *ThumbnailSizeKey = @"com.masakih.BSInlinePreviewer.thumbnailSiz
128128 return NO;
129129 }
130130
131- // get insert position.
132- NSRange linkRange;// = [self linkRange];
133- {
134- unsigned charIndex_ = [self actionIndex];
135- NSTextStorage *ts = [self targetTextStorage];
136-
137- NSRange limit;
138- if(charIndex_ > 100) {
139- limit = NSMakeRange(charIndex_ - 100, 200);
140- } else {
141- limit = NSMakeRange(0, 200);
142- }
143- unsigned over = NSMaxRange(limit) - [ts length];
144- if(over > 0) {
145- limit.length -= over;
146- }
147-
148- id attr = nil;
149- id checked = nil;
150- @try {
151- attr = [ts attribute:NSLinkAttributeName
152- atIndex:charIndex_
153- longestEffectiveRange:&linkRange
154- inRange:limit];
155- // NSLog(@"link attr -> %@", attr);
156- // NSLog(@"attr range -> %@", NSStringFromRange(longest));
157-
158- checked = [ts attribute:BSInlinePreviewerPreviewed
159- atIndex:charIndex_
160- longestEffectiveRange:NULL
161- inRange:limit];
162- }
163- @catch(NSException *ex) {
164- if([[ex name] isEqualToString:NSRangeException]) {
165- linkRange.location = NSNotFound;
166- } else {
167- @throw;
168- }
169- }
170-
171- if(!attr) {
172- linkRange.location = NSNotFound;
173- }
174- if(checked) {
175- linkRange.location = alreadyPreviewed;
176- }
131+ NSUInteger charIndex_ = [self actionIndex];
132+ NSTextStorage *ts = [self targetTextStorage];
133+
134+ NSRange limit;
135+ if(charIndex_ > 100) {
136+ limit = NSMakeRange(charIndex_ - 100, 200);
137+ } else {
138+ limit = NSMakeRange(0, 200);
177139 }
178- if(linkRange.location == NSNotFound) {
179- NSLog(@"con not found insert position.");
180- return NO;
140+ NSUInteger over = NSMaxRange(limit) - [ts length];
141+ if(over > 0) {
142+ limit.length -= over;
181143 }
182- if(linkRange.location == alreadyPreviewed) return NO;
183-
184- BSILinkInfomation *link = [[[BSILinkInfomation alloc] init] autorelease];
185- link.urlString = [url absoluteString];
186- link.range = linkRange;
187-
188- [self downloadAndInsertImages:@[link]];
144+ NSArray *links = [self linksForRange:limit];
145+
146+ [self downloadAndInsertImages:links];
189147
190148 return YES;
191149 }
@@ -220,18 +178,23 @@ static NSString *ThumbnailSizeKey = @"com.masakih.BSInlinePreviewer.thumbnailSiz
220178 return NO;
221179 }
222180
223- // get insert position.
224- NSMutableArray *links = [NSMutableArray array];
181+ NSArray *links = [self linksForRange:[threadView selectedRange]];
225182
226- NSRange selectedRange = [threadView selectedRange];
227- NSTextStorage *ts = [self targetTextStorage];
183+ [self downloadAndInsertImages:links];
228184
229- NSUInteger selectionMax = NSMaxRange(selectedRange);
185+ return YES;
186+}
187+
188+- (NSArray *)linksForRange:(NSRange)range
189+{
190+ NSMutableArray *links = [NSMutableArray array];
191+ NSTextStorage *ts = [self targetTextStorage];
192+
193+ NSUInteger selectionMax = NSMaxRange(range);
230194 id attr = nil;
231195 BOOL didChecked = NO;
232- NSUInteger location = selectedRange.location;
196+ NSUInteger location = range.location;
233197 NSRange longest;
234- NSRange range = selectedRange;
235198 do {
236199 attr = [ts attribute:NSLinkAttributeName
237200 atIndex:location
@@ -240,7 +203,7 @@ static NSString *ThumbnailSizeKey = @"com.masakih.BSInlinePreviewer.thumbnailSiz
240203 didChecked = ([ts attribute:BSInlinePreviewerPreviewed
241204 atIndex:location
242205 longestEffectiveRange:NULL
243- inRange:range]) ? YES : NO;
206+ inRange:range]) ? YES : NO;
244207 if(!didChecked && [self isValiableLinkAttr:attr]) {
245208 BSILinkInfomation *link = [[[BSILinkInfomation alloc] init] autorelease];
246209 link.urlString = [self URLStringFromAttr:attr];
@@ -251,11 +214,8 @@ static NSString *ThumbnailSizeKey = @"com.masakih.BSInlinePreviewer.thumbnailSiz
251214 range.length -= longest.length;
252215 } while(location < selectionMax);
253216
254- [self downloadAndInsertImages:links];
255-
256- return YES;
217+ return links;
257218 }
258-
259219 - (BOOL)validateLink:(NSURL *)anURL
260220 {
261221 NSArray *imageExtensions;
@@ -365,11 +325,11 @@ static NSString *ThumbnailSizeKey = @"com.masakih.BSInlinePreviewer.thumbnailSiz
365325 {
366326 return textStrage;
367327 }
368-- (void)setActionIndex:(unsigned)p
328+- (void)setActionIndex:(NSUInteger)p
369329 {
370330 actionIndex = p;
371331 }
372-- (unsigned)actionIndex
332+- (NSUInteger)actionIndex
373333 {
374334 return actionIndex;
375335 }